Dheeraj Chakravarthi Dheeraj Chakravarthi - 6 months ago 13
Linux Question

Sorting according to a character position in linux

ABCDB3147215$T91907742d32f9e218b9babb5e80e24cb
ABCDB3403$25341736
ABCDB3540178$T0c2c1bd2eece7fa7c1e58f1111ef506e
ABCDB3940$25797287
ABCDB3977034$Ta13e61d2cf17fc5b641c01a5d097512c
ABCDB3444726$25341239
ABCDB3686150$25341881
ABCDB391702$25341848
ABCDB3023$25752571
ABCDB3633266$25341420
ABCDB3$25341517
ABCDB387318$25341883
ABCDB3095545$25815202
ABCDB318$25328916
ABCDB316848$T58e5545607d7ca0fb276a69741f8f6f


I have to sort this file according to the text after the '$' symbol. The position of $ in the file is not constant across all the lines in the file.

Is there any way to do this using the sort command? (Also share if there's any other way to do this)

Answer
sort -t'$' -k2

Sets the field delimiter to a dollar sign and then uses the second field through the end of the line as a sort key.

Comments