[Cialug] PerlRE
Chris Freeman
cwfreeman at gmail.com
Sun Sep 2 10:04:21 CDT 2007
man perlretut or http://perldoc.perl.org/perlretut.html.
I'll create an example for you which will capture 'We go to the ' plus one
word terminated by a period, EOL, or non-word character. Be careful, as
hyphenated places will not be included. Also, if the place is on the next
line, or the spaces are wrong, we won't catch that either.
Create a file:
>>>>>>>START-OF-FILE<<<<<<<<<<
#!/bin/perl
while(<>) {
if( $_ =~ /(We go to the \w+)($|\W|\.)/ ) {
print $1 . "\n";
}
}
>>>>>>>END-OF-FILE<<<<<<<<<<
Chris
On 9/2/07, Todd Walton <tdwalton at gmail.com> wrote:
>
> Can someone refresh my memory? I have a file with many lines of text.
> One (or two) of those lines has an expression in it, "We go to the ",
> followed by another one word. I want to use perl to find that
> expression and print "We go to the park" or "We go to the game" or
> whatever it is. How do I do that?
>
> So far I know that -e will run a perl command from the shell command
> line. And I saw a -Fpattern in man perl, but I couldn't find anything
> else on command-line options in man perl. I did find a page about it
> on perl.com and then at the end of that article it said to see 'man
> perlrun'. So I'm all over that.
>
> But how do I yank and return just "We go to the " out of it?
>
> -todd
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cialug.org/pipermail/cialug/attachments/20070902/ffdf40f0/attachment.html
More information about the Cialug
mailing list