![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need immediate help with sorting!!! | sasuke_uchiha | Shell Programming and Scripting | 9 | 08-06-2008 12:07 AM |
| trying to cope with awk difficulties | amatuer_lee_3 | Shell Programming and Scripting | 8 | 05-11-2008 05:46 PM |
| Proxy ARP Difficulties | TheMaskedMan | IP Networking | 7 | 11-02-2005 10:14 AM |
| Sorting mp3 | penguin-friend | Shell Programming and Scripting | 3 | 05-13-2005 04:21 AM |
| Simple Network Program Difficulties | Mistwolf | High Level Programming | 2 | 03-19-2002 06:34 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Sorting Difficulties
Hey guys,
I am sort of new to unix and I am having difficulty sorting. What I am trying to do is sort a particular field in reversed order and another field in alphabetic order to create a new file that looks like this: MILLER,EDWARD AL 14 101293 9341 MOORE,HENRY 15 101297 9077 NGUYEN,LE HUU 13 101314 9576 *NOTE THAT THE SPACINGS ARE NOT DISPLAYED CORRECTLY; IT SHOULD BE ALL LINED UP here is what I tried: sort -r +0.20 -0.24 +0.00 -0.16 "input file" > "output file" Basically, "+0.20 -0.24" represents the first two digit numbers that needs to be reversed and "+0.00 -0.16" represents the names that needs to be in alphabetic order. can someone help me? Last edited by nthamma; 09-21-2008 at 03:40 PM.. |
|
||||
|
I got it sorted!
What I did was give out this command: sort-r +0.20 -0.24 -k 1,1d "input file" > "output file" I could not specify the field for the two digit numbers because the names are not homogeneous. What I mean by that is that some of the names have 1 field and some of them have 2 fields: Code:
MILLER,EDWARD AL 14 101293 9341 MOORE,HENRY 15 101297 9077 NGUYEN,LE HUU 13 101314 9576 So, what I did was count the spaces and use columns to specify the two digit numbers and reversed them. Next, I used the -k option to specify the 1st field for the names in alphabetic order using -d (sort in "phone directory" order). And it made my day! Took me so long to figure that one out and your replies really helped me understood how the whole thing works. Thanks for your help! Last edited by Perderabo; 09-21-2008 at 05:32 PM.. Reason: Add code tags for readability |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|