regarding sort command.

hi,

In UNIX I want a sort records in a file based on the certain position in the record as the key in the file.

Now if certain 2 records have the same record then the out file should have the records as the First in First out i.e. in the same order in which they occur in the input file.

Say for e.g.

There are records in the input file

12345555555555677689870987
12345
12343

And I sort it based on the the keys 1-4 so then as per the sort I need

Output file

1234555555555555555
12345
12343

but the output I get is something like this

12343
12345
12445555555555555

i.e. it gets soreted on the next one records also if the key is the same which I don't want it to happen.

Could someone please let me know if this is possible using the sort command in UNIX or any other way to do it.

Thanks
Aman.

This works for me

 sort -k 1.1,1.4 test.dat

That doesn't work for me. I get the same result as the OP. But this does the trick:

nl -ba < inputfile | sort -k2.1,2.4 -k1n | cut -f2- > outputfile