in reply to Search for a string in a file
$ perl -n -e 'print if $_ eq "PEAR\n"' infile > outfile
or
$ perl -n -e 'print if /^PEAR$/' infile > outfile
The part in single quotes (the argument to the -e option) is the Perl script. The -n option is equivalent to putting while (<>) { ... } around the code.
$_ eq "PEAR\n" or /^PEAR$/ tests if the current line (the default variable $_ here) holds your search string, where $_ =~ /.../ is implicitly assumed in the second case, i.e. a regular expression is by default matched against $_.
|
|---|