On Jan 28, Mayank said: >How can i have an equivalent of following UNIX command in PERL? >sort -t "|" -k 11,11 $file1 > $file2 >Which means sort file "$file1" on the basis of 11th field with "|" as >the delimiter
You can do it the "long" way: my @orig; open FILE, "< $file1" or die "can't read $file1: $!"; # choose one of these two methods @orig = map [ split /\|/ ], <FILE>; # or # push @orig, [ split /\|/ ] while <FILE>; close FILE; open OUT, "> $file2" or die "can't write $file2: $!"; print OUT map { join "|", @$_ } sort { $a->[10] cmp $b->[10] } # arrays are 0-based, not 1-based @orig; close OUT; In case anyone is wondering about newlines, I never removed them, so I don't need to replace them. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]