Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > can Perl Sort do this, unix sort breaks on it (muliple spaces as demiliter)

Reply
Thread Tools

can Perl Sort do this, unix sort breaks on it (muliple spaces as demiliter)

 
 
colin_lyse
Guest
Posts: n/a
 
      02-02-2005
runing Sun Unix 5.8 on Sun-Fire-15000

i have a small file (20k) that looks like the following. some fields have 1
space between them, others 2, others more. (. = space)

00290..S.....33.XS798............SUB.......SUB ACTIVE 19971202
00090..S.... 69KV..TSS30 TR LTC TR2 ACTIVE 20050201
00135..S.... 69KV..TSS30 TRLTC TR1 ACTIVE 20050201

the problem is that when i do the following

sort +2 -3 it works the 3rd the list is correctly sorted in the third column.
however, if I want to sort on the 4 colum and do

sort +4 -5 it does not work (see example above), it sorts by the 4th column
only in relation to the 3rd column (x goes first because of the 33), howve i
think it might be related to the 1 vs. 2 spaces.

I though about replacing the spaces with tabs, however some of the fields have
spaces within them leading to problems with alignment.

i also tried
sort -n -k 5,5 -k 4,4 -k 6,6 but that didn't work only if i stoped after
field 3

It seems like the problem is that after field 3 there are differing amounts of
space between fields .


Can Perl Sort do this, new to perl. any help greated appreciated.
 
Reply With Quote
 
 
 
 
Tore Aursand
Guest
Posts: n/a
 
      02-03-2005
colin_lyse wrote:
> [...]
> Can Perl Sort do this, new to perl. any help greated appreciated.


Yes, Perl can help you;

perldoc -f sort
perldoc -q sort


--
Tore Aursand <>
"I know not with what weapons World War 3 will be fought, but World War
4 will be fought with sticks and stones." (Albert Einstein)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl sort different from unix sort Jose Luis Perl Misc 3 03-03-2011 09:14 PM
[CSS] how can I show spaces as spaces? Tomasz Chmielewski HTML 21 09-10-2009 06:43 PM
how can I show spaces as spaces, part 2 Tomasz Chmielewski HTML 14 09-10-2009 03:54 PM
my own perl "dos->unix"/"unix->dos" Robert Wallace Perl Misc 7 01-21-2004 11:28 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM



Advertisments