Computing.Net > Forums > Unix > Need help with sorting a file

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.

Need help with sorting a file

Reply to Message Icon

Name: raj2134
Date: June 8, 2005 at 09:38:16 Pacific
OS: Unix
CPU/Ram: SOLARIS
Comment:

Guys, I am new to UNIX world and really need help of your expertise.

I have file with each line of fixed length
eg.,

DT00123 1234 FFF 56565
DT00923XX3425ZZFFFYY34281

As you can see there is no fix delimeter, I want to sort the file on column which starts at char position 10 and ends at position 14

The position of the field and length of the line is fixed. So I can very well rely upon the column start and charcter position.

I was exploring the possibilities with sort but it seem it requires the delimeter to define the field.

Any script using sort, awk, sed is fine.




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: June 8, 2005 at 10:50:50 Pacific
Reply:

By default, white space is the field delimiter for sort. Why don't you choose a character for a delimiter that isn't used so the entire line is a single field and then sort on positions 10 to 14:

sort -t~ -k 1.10,1.14 mysort.txt


0

Response Number 2
Name: raj2134
Date: June 8, 2005 at 21:04:54 Pacific
Reply:

Fields are created with user input so I don't want to depend upon some character, because that might appear sometime.

I tried,

sort -n +0.10 -0.13 filename

and this worked fine for me. But as the manual says that this is the obsolete way. Now I want to be sure that this will cause problems to me in future.

Thanks in advance


0

Sponsored Link
Ads by Google
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: Need help with sorting a file

HELP!!!! with Write a script. www.computing.net/answers/unix/help-with-write-a-script/4918.html

help with analog.cfg file on virtual ser www.computing.net/answers/unix/help-with-analogcfg-file-on-virtual-ser/3152.html

Unzip a file from multiple file zip www.computing.net/answers/unix/unzip-a-file-from-multiple-file-zip/7601.html