Re: best way to search in a file

2008-10-07 Thread Paul Johnson
On Tue, Oct 07, 2008 at 10:07:21AM -0700, John W. Krahn wrote: > [EMAIL PROTECTED] wrote: >> This one-liner does pretty much what I would want but I do not know >> how to convert it to a script. >> perl -lane 'print $F[2] if /searchterm/' input.txt > > #!/usr/bin/perl > $\ = "\n"; > while ( <> ) {

Re: best way to search in a file

2008-10-07 Thread John W. Krahn
[EMAIL PROTECTED] wrote: What is the easiest method to search in a file for a particular term, and output a desired field. For example, in awk, I would simply do: awk '/searchterm/ {print $2}' input.txt to get my result. But in Perl, the shortest way I could find achieve the same result was:

Re: best way to search in a file

2008-10-07 Thread Mr. Shawn H. Corey
On Mon, 2008-10-06 at 14:26 -0700, [EMAIL PROTECTED] wrote: > This one-liner does pretty much what I would want but I do not know > how to convert it to a script. > > perl -lane 'print $F[2] if /searchterm/' input.txt See `perldoc perlrun` and look up -a and -n under "Command Switches". -- Jus

best way to search in a file

2008-10-07 Thread [EMAIL PROTECTED]
What is the easiest method to search in a file for a particular term, and output a desired field. For example, in awk, I would simply do: awk '/searchterm/ {print $2}' input.txt to get my result. But in Perl, the shortest way I could find achieve the same result was: $inputfile=input.txt; open(