Sort a file from specific row onwards

Hello All:

I've file in below format. File name is "FIRSTN.TBL":

AAAAAA N
BBBBBBBBBBBBBBBBBBBBBBB N
.
.
.
.
ZZZZZZZZZZZZZZZZZZZZZZZZZZ N

My file row length is 40 characters and my second column will start from 25th column and it is only one letter. My file having 20177 total records.

I want to sort from 500th row to end of file. Can anyone advice me how to sort FIRSTN.TBL from 500th row to end of file.

Thanks for your help in advance.
PS: I am using "SuSE Linux Enterprise Server 9" platform

  • Eswar

first extract the rows from 500 to last in a temp file. sort that file , then concat with the first 500 rows of original file.

head -n500 FIRSTN.TBL >temp.txt
head -n-500 FIRSTN.TBL |sort >>temp.txt

temp.txt will have the result.

Kumaran:

Thanks for your reply. My requirement is to sort a file FROM 500TH row onwards to END OF FILE but NOT first 500 lines.

the first line will extract the first 500 lines into a new file without any sort. this is optional if you require this 500 lines to be present in the output.

The second command will extract lines from 500 till last and sort and will append the result in the previous file.

this will only take lines starting from 501 and do the sort.

head -n-500 FIRSTN.TBL|sort >result.txt