![]() |
|
|
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 |
| Reversing file order using SED | MBGPS | Shell Programming and Scripting | 3 | 01-07-2009 10:10 AM |
| creating a file in reverse order of another file | srilaxmi | Shell Programming and Scripting | 3 | 11-28-2008 12:54 AM |
| sort a file in reverse order | frustrated1 | Shell Programming and Scripting | 11 | 09-21-2005 04:41 PM |
| look in file, seperate letters, put in order... | chekeitout | UNIX for Advanced & Expert Users | 3 | 11-05-2004 05:00 PM |
| Sorting filenames by order in another file | samudimu | UNIX for Advanced & Expert Users | 4 | 05-24-2002 01:03 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi -
I have a file with lots of lines in that I need to order based on the number of commas! e.g the file looks something like :- cn=john,cn=users,cn=uk,dc=dot,dc=com cn=john,cn=users,dc=com cn=users,cn=groups,dc=com cn=john,cn=admins,cn=users,cn=uk,dc=dot,dc=com cn=fred,cn=users,cn=uk,dc=dot,dc=com cn=simon,cn=users,cn=uk,dc=dot,dc=com cn=users,dc=com I need to order the file so that it ends up like :- cn=john,cn=admins,cn=users,cn=uk,dc=dot,dc=com cn=john,cn=users,cn=uk,dc=dot,dc=com cn=fred,cn=users,cn=uk,dc=dot,dc=com cn=simon,cn=users,cn=uk,dc=dot,dc=com cn=john,cn=users,dc=com cn=users,cn=groups,dc=com cn=users,dc=com I am hoping someone knows some sed or awk that can do this ? ![]() Many thanks |
|
||||
|
Code:
my @lines=<DATA>;
print map {$_->[0]}
sort {$b->[1] <=> $a->[1]}
map {[$_,tr/,//]} @lines;
__DATA__
cn=john,cn=users,cn=uk,dc=dot,dc=com
cn=john,cn=users,dc=com
cn=users,cn=groups,dc=com
cn=john,cn=admins,cn=users,cn=uk,dc=dot,dc=com
cn=fred,cn=users,cn=uk,dc=dot,dc=com
cn=simon,cn=users,cn=uk,dc=dot,dc=com
cn=users,dc=com
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|