On a unix system:grep 'gateway' infile > outfile
On a Windows system:perl -ne'print if /gateway/' infile > outfile
perl -ne"print if /gateway/" infile > outfile
An example using file handles:
# Usage: script.pl infile outfile # or # Usage: perl script.pl infile outfile use strict; use warnings; my ($qfn_in, $qfn_out) = @ARGV; open(my $fh_in, '<', $qfn_in) or die("Unable to read file \"$qfn_in\": $!\n"); open(my $fh_out, '>', $qfn_out) or die("Unable to create file \"$qfn_out\": $!\n"); while (<$fh_in>) { if (/gateway/) { print $fh_out $_; } }
Update: Fixed copy & paste error mentioned in reply.
Update: Must have been asleep! Fixed missing my mentioned in reply.
In reply to Re: search and extract lines which contain a word
by ikegami
in thread search and extract lines which contain a word
by m@cky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |