sumathigokul has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, i want to search in a text file for '2' and copy the whole statement in another text file. Here is the code. It prints those matched statements and it also generated new.txt file, but the file is empty.
use strict; my $find = "2"; open (FILE, "<high_fanout.txt") or die "could not open:$!"; my @line = <FILE>; for (@line) { if ($_ =~ /$find/) { print "$_\n"; print NEW "@line\n"; } } open (NEW, ">new.txt" ) or die "could not open:$!"; close (FILE); close (NEW);
can anyone help me out from this mistake? Thank you all.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Perl script to find particular string and save those lines in another file?
by graff (Chancellor) on May 05, 2015 at 05:24 UTC | |
by sumathigokul (Acolyte) on May 05, 2015 at 06:11 UTC | |
Re: Perl script to find particular string and save those lines in another file?
by aaron_baugher (Curate) on May 05, 2015 at 05:39 UTC | |
Re: Perl script to find particular string and save those lines in another file?
by hdb (Monsignor) on May 05, 2015 at 05:25 UTC |
Back to
Seekers of Perl Wisdom