![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sorting a file | mtechnocrat | UNIX for Dummies Questions & Answers | 11 | 06-28-2007 07:28 AM |
| need help with sorting a file | pieman8080 | Shell Programming and Scripting | 5 | 11-21-2006 01:50 PM |
| Sorting a file | Khoomfire | Shell Programming and Scripting | 2 | 12-13-2005 07:48 AM |
| sorting file | sx3v1l_1n51de | Shell Programming and Scripting | 4 | 06-22-2005 01:16 PM |
| Help sorting file. | gio123bg | Shell Programming and Scripting | 3 | 12-10-2003 10:15 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
file sorting
i have a data in afile like this
************************************** sree sree@yahoo.com 98662323432 ************************************* phani phani@yahoo.com 98662323344 ************************************* i want to sort the file with respect to name. how can i do this. thank u,inadvance |
|
||||
|
thank you
hi
paste -s -d "\t\t\t\n" filename|sort -d -k2,2|tr "\t" "\n" sorry to tell this, i unable to understand this code. actually i am sorting the file in alphabetical order. will u please send me some detailed code or an example. thank you ramesh |
|
||||
|
hi
What i tried was to join the 4 lines(which form a group) into a single line and then sort bsed on the required key and then get back the old format.
Input data - Quote:
Code:
1) paste -s -d "\t\t\t\n" filename gives xrkrb@chu10t1: /home/xrkrb/unix_forum>paste -s -d "\t\t\t\n" mytestfile ************************************** sree sree@yahoo.com 98662323432 ************************************* phani phani@yahoo.com 98662323344 ************************************* 2) then you sort the lines based on the second field which is the name 3) get back the original format as it existed in the original file - this is done by 'tr' Last edited by ranj@chn; 11-25-2006 at 08:51 AM.. Reason: typo errors |
|
||||
|
Quote:
Code:
paste -s -d "\t\t\t\n" filename|sort -d -k2,2|tr "\t" "\n" > tmp mv tmp filename |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|