tried further, still no resolution: file1 = (space seperated values) outputfile = (colum1, and 5 onwards) field seperator would be space. from linux: cut -f1,5- -d" " file |grep -v "^0" | sort -n > to_file; open(tmpFH,"<","file1"); @tmpAR = <tmpFH>; close(tmpFH); foreach $line (@tmpAR) { @tmpAR2 = split(/ /,"$line"); $line2 = "$tmpAR[0] $tmpAR[5..-1]"; push(@tmpAR3,$line2); }; @tmpAR3 = sort(@tmpAR3); print @tmpAR3;
From: Rajeev Prasad <rp.ne...@yahoo.com> To: Rajeev Prasad <rp.ne...@yahoo.com>; Perl Beginners <beginners@perl.org> Sent: Thursday, September 1, 2011 6:50 PM Subject: Re: how to do this in perl (from unix) I tried this open(tmpFH,"<","somefile"); @tmpAR = <tmpFH>; close(tmpFH); push(my @tmpAR2,$tmpAR[0]); push (@tmpAR2,$tmpAR[5..-1]); my @tmpAR3 = grep {!/^0 /} @tmpAR2; @tmpAR3 = sort(@tmpAR3); print @tmpAR3; but getting error: Argument "" isn't numeric in array element at ./test.pl line 31. output is not coming correct, only first row of original file is coming..... From: Rajeev Prasad <rp.ne...@yahoo.com> To: Perl Beginners <beginners@perl.org> Sent: Thursday, September 1, 2011 6:38 PM Subject: how to do this in perl (from unix) from linux: cut -f1,5- -d" " file |grep -v "^0" | sort -n > to_file; <======this line: how to achieve this in perl? will below work, in perl? if ( ! -s $sourcedir/somefile ){ open(tmpFH,"<","file2"); @tmpAR = <tmpFH>; close(tmpFH); push(@tmpAR2,$tmpAR[0],$tmpAR[5..]); #select on columns 1 and 5 onwards from the original file my @tmpAR3 = grep {!^[0 ]} @tmpAR2; #omit line with 0 in the beginning @tmpAR3 = sort(@tmpAR3); # sort on the first column } we can then print tmpAR3 to a file. plz. advice. thx.