muchyog has asked for the wisdom of the Perl Monks concerning the following question:
Hi I am trying to read line no 17 to 30 of a file and write the output to a new file. I am able to do this using a command line :
perl -ne 'print if $. >= 17 && $. <= 30' infile.txt > output.txt
But the same thing I try doing within script I am unable to Here is the code which I am using:
Let me know the right way of doing this.#/usr/bin/perl -w my $outFile= ">/home/eyogmuc/Yogesh/Technical/Perl/output.txt"; my $inFile= "/home/eyogmuc/Yogesh/Technical/Perl/infile.txt"; open INFILE, $inFile or die "Can't open $inFile : $!"; open OUTFILE, $outFile or die "Can't open $outFile : $!"; #system(`print if $. >= 17 && $. <= 30 INFILE >> OUTFILE`); system("'print if $. >= 17 && $. <= 30' infile.txt > output.txt" ); close INFILE or die "can't close $inFile : $!"; close OUTFILE or die "can't close $outFile : $!";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: System command not working
by NetWallah (Canon) on Jul 10, 2012 at 06:03 UTC | |
Re: System command not working
by kcott (Archbishop) on Jul 10, 2012 at 06:43 UTC | |
by muchyog (Novice) on Jul 10, 2012 at 06:52 UTC | |
by kcott (Archbishop) on Jul 10, 2012 at 07:51 UTC | |
by aitap (Curate) on Jul 10, 2012 at 07:19 UTC | |
by monsoon (Pilgrim) on Jul 10, 2012 at 15:04 UTC | |
by Jim (Curate) on Jul 10, 2012 at 22:00 UTC | |
Re: System command not working
by jwkrahn (Abbot) on Jul 10, 2012 at 09:50 UTC | |
Re: System command not working
by monsoon (Pilgrim) on Jul 10, 2012 at 06:09 UTC |
Back to
Seekers of Perl Wisdom