in reply to search and extract lines which contain a word
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: search and extract lines which contain a word
by cdarke (Prior) on Mar 26, 2008 at 12:36 UTC | |
|
Re^2: search and extract lines which contain a word
by rudder (Scribe) on Mar 26, 2008 at 14:52 UTC | |
by ikegami (Patriarch) on Mar 26, 2008 at 18:02 UTC | |
|
Re^2: search and extract lines which contain a word
by m@cky (Initiate) on Mar 27, 2008 at 06:38 UTC | |
by m@cky (Initiate) on Mar 27, 2008 at 10:05 UTC | |
by ikegami (Patriarch) on Mar 27, 2008 at 11:36 UTC | |
by ikegami (Patriarch) on Mar 27, 2008 at 11:28 UTC | |
by stiller (Friar) on Mar 27, 2008 at 11:24 UTC |