How to sort a file based on field postion?
For eg. I need to sort the below given file. Based on 4th,5th and 8th positions. Please help. I tried the following command, i
Try this command:
sort -k4,4 -k5,5 -k8,8 input.txt
From the sort
manual:
-k, --key=POS1[,POS2]
start a key at POS1, end it at POS2 (origin 1)
POS is F[.C][OPTS], where F is the field number and C the character position in the field. OPTS is
one or more single-letter ordering options, which override global ordering options for that key. If
no key is given, use the entire line as the key.
In your command:
-k 3.42,44
means start from (42th char of 3rd field) to (44th field)
.
Do you mean -k 3.42,3.44
?