I have a requirement whereby I have to sort a flat file based on Multiple Columns (similar to ORDER BY Clause of Oracle). I am getting 10 columns in the flat file and I want the file to be sorted on 1st, 3rd, 4th, 7th and 9th columns in ascending order. The flat file is pipe seperated.
Any help will be highly appreciated.
Well I am not too sure what you exactly want the output to be but sort +1 -2 +3 -4 will sort the output based on 2nd field and if second field is same it will see the next specified field in this case it is 4th field.
I had given the examples below
# cat junk [This is a junk file which contains data]
5 3 2 9
3 4 1 7
5 2 3 1
6 1 3 6
1 2 4 5
3 1 2 3
5 2 2 3
# sort +1 -2 +3 -4 junk [sort based on the 2nd and 4th field]
3 1 2 3
6 1 3 6
5 2 3 1
5 2 2 3
1 2 4 5
5 3 2 9
3 4 1 7
# sort +1 -2 junk [sort based on the 2nd field]
3 1 2 3
6 1 3 6
1 2 4 5
5 2 2 3
5 2 3 1
5 3 2 9
3 4 1 7
# sort +1 +3 junk [See here it is same as sort +1 it checks for the 3rd field if the 2nd field is same, it does not go for the 4the field ]
3 1 2 3
6 1 3 6
5 2 2 3
5 2 3 1
1 2 4 5
5 3 2 9
3 4 1 7
# sort +1 junk
3 1 2 3
6 1 3 6
5 2 2 3
5 2 3 1
1 2 4 5
5 3 2 9
3 4 1 7
#
If this is not what you wanted, post your data and the expected output whatever you want, we will look into that
should be sorted on 0th field i.e 1705614
1705614
Then on 4th field i.e C ( C is should come first)
U
Should both be the 'C' s,
sort on 3rd field i.e 99 (Ascending)
88
Should both be the same numbers,
sort on 2nd field i.e 2 (descending)
1
I hope I am clear...Thanks
but In the above case I need the data in reverse, because column 5 should be preferred for 'C', only in case if both are 'C's or 'U's then i want this to be sorted on the last column i.e date