Simple question to experts

L

Luca Villa

Hi all!

The simple problem is this: I have a file named example.html on my
harddisk and I want to extract from that file a block of text that
goes from the regex "foobar[0-9]" to the first occurrence of the regex
"abcdef[0-9]".
What's the Perl/command-line/single-line solution for this?

Thanks in advance for any help
 
P

Paul Lalli

Subject: Simple question to experts Options

Please put the subject of your post in the Subject of your post.
The simple problem is this: I have a file named example.html on my
harddisk and I want to extract from that file a block of text that
goes from the regex "foobar[0-9]" to the first occurrence of the
regex "abcdef[0-9]".
What's the Perl/command-line/single-line solution for this?

It's my birthday, and I'm feeling generous. Here, have a fish:

perl -ln0777 -e'print $1 if /foobar[0-9](.*?)abcdef[0-9]/'
example.html

Then read:
perldoc perlrun
perldoc perlre
to understand what's happening.

Paul Lalli
 
T

Tad McClellan

Paul Lalli said:
It's my birthday,


Those are good for you.

A federally funded study has shown that people with the most birthdays...

....

....

.... live the longest.
 
P

Paul Lalli

Luca Villa wrote:
The simple problem is this: I have a file named example.html on
my harddisk and I want to extract from that file a block of text
that goes from the regex "foobar[0-9]" to the first occurrence
of the regex "abcdef[0-9]".
What's the Perl/command-line/single-line solution for this?

Look for "Range Operators" (scalar context) in `perldoc perlop`.

perl -n -e 'print if /foobar\d/ .. /abcdef\d/' example.html

That will include all text before /foobar\d/ on the first line, and
all text after /abcdef\d/ on the last line. The OP said he wanted the
text that is between the two patterns.

Paul Lalli
 
T

Ted Zlatanov

JG> But did they find a causal relationship, or was it more of a
JG> statistical correlation?

It's causal. Those pesky February 29 birthdays keep throwing the
statistics off :)

Ted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top