Computing.Net > Forums > Unix > Sort file by position

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Sort file by position

Reply to Message Icon

Name: covina
Date: March 14, 2007 at 13:00:57 Pacific
OS: AIX5.3
CPU/Ram: 555
Product: AIX
Comment:

I want to sort the following file by full name
i.e., position 15-52, using sort command. Any help will be appreciated.
E77377370007673777373Bobbinn-Bashy, Handa J +0073300706077
E77377370006673777373Bobbinn-Bashy, Handa J +0079000706070
E77377770006793660076Cirillo, Beth M -0065670706070
E77377370007637333676Williams, Winters T -0037730706077
E77377370006637333676Williams, Winters T -0037300706070
E77377370006637333676Williams, Winters T -0075300706070
E77377770006637566676Williams, Algie J -0076000706070
E77377770007665353675Wilson, Selman H +0076000706077
E77377770007635633563Glenn, Latricia J +0076330706077
E77377370007637336377Horn, Rebecca C +0035050706077
E77377370007700366507Oliver, Melvin B +0036600706077
E77377370006700366507Oliver, Melvin B +0063000706070
E77377770007635390373Bells, Lucia +0077670706077
E77377770006635390373Bells, Lucia +0030000706070
E77377370006673965077Walters, Monk L +0077000706070
E77377770006635739909Bunter, Brenda A +0075730706070
E77377770007635766977Airington, Lucia +0076000706077
E77377770007357305767Miller-Marozi, Fancy C +0076000706077
E77377770006637637093Harris, Lora A +0063330706070
E77377770007639770073Wilamsons, Yvonne +0076330706077
E77377770006639770073Wilamsons, Yvonne +0037670706070
E77377370006367953636Ball, Gita S +0067300706070

TIA



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 14, 2007 at 18:41:31 Pacific
Reply:

First, the positions you want to sort by do not agree with your data file. Therefore, I choose to sort by characters 22 to 30

sort -t \& -k 1.22,1.30 myfile

Since sort by default uses white space for a field delimiter, I choose & because it isn't used ensuring that each record is treated as 1 field. Change the positions to what fits your purpose.

I then use the -k option that allows be to sort field 1 from character position 22 to 30.


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Sort file by position

How to find out the file by hour www.computing.net/answers/unix/how-to-find-out-the-file-by-hour/8129.html

Creating a script to sort a file www.computing.net/answers/unix/creating-a-script-to-sort-a-file/4361.html

sorting recoreds in a file www.computing.net/answers/unix/sorting-recoreds-in-a-file/7994.html