John W. Krahn wrote:
Rajeev Prasad wrote:
from linux:

cut -f1,5- -d" " file |grep -v "^0" | sort -n> to_file;<======this
line: how to achieve this in perl?


open IN_FH, '<', 'file' or die "Cannot open 'file' because: $!";
open OUT_FH, '>', 'to_file' or die "Cannot open 'to_file' because: $!";

print OUT_FH sort { $a <=> $b } map join( " ", ( split / +/, $_, 5 )[ 0,
-1 ] ), <IN_FH>;

Correction!  I forgot the grep part:

open IN_FH,  '<', 'file'    or die "Cannot open 'file' because: $!";
open OUT_FH, '>', 'to_file' or die "Cannot open 'to_file' because: $!";

print OUT_FH sort { $a <=> $b } map /^0/ ? () : join( ' ', ( split / +/, $_, 5 )[ 0, -1 ] ), <IN_FH>;




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to