[ale] NewbieQ Perl filtering question

Mike Fletcher fletch at phydeaux.org
Fri Jun 30 09:29:05 EDT 2006


On Jun 29, 2006, at 4:57 PM, Mills, John M. wrote:

> ALErs -
>
> I need to return only the part of a text line that falls between two
> expected character strings, as it:
>
> Input: blah..blah..string1<good content>string2..garbage..garbage
> Output: <good_content>

The one-liner from the command line version would be:

perl -lne '/string1(.*?)string2/ && print $1' infile > outfile

or to do it in-place (making a copy of the original infile in  
infile.bak)

perl -i.bak -lne '/string1(.*?)string2/ && print $1' infile




More information about the Ale mailing list