hi all
i have file call file_1 which contains names of other files like this
9999999-200-4545454-1
9999999-200-4545222-2
9999999-300-8751252-1
i want to sort the file that the record will be sorted according to the last variable .in this case (1 and 2) after the sort i want the new file file_2 contains the record in this order
9999999-200-4545454-1
9999999-300-8751252-1
9999999-200-4545222-2
i wrote something like this
sort file_1 -o file_2 -k 21,21 -S 22
nothing !!
i don't understand what is the problem
can someone help me please ?
best regards
Try
sort -k 1.21,1.21 file1 > file2
You only have one field in this file as far as sort is concerned. For more information read the section on the defination of a field in the sort manpage.
At least in SUSE, the sort command is like this:
sort [OPTIONS] ... [FILE]
you had the file before the options.
Try this instead (it worked for me):
sort -k 21 -o file_2 -r file_1
Option r (reverse order) is used because otherwise it was sorting in Descending mode. In option k, the top limit is optional, and so it is not needed if you are sorting with one character only.