Simple question to experts

Discussion in 'Perl Misc' started by Luca Villa, Nov 5, 2007.

  1. Luca Villa

    Luca Villa Guest

    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
     
    Luca Villa, Nov 5, 2007
    #1
    1. Advertising

  2. Luca Villa

    Paul Lalli Guest

    On Nov 5, 7:51 am, Luca Villa <> wrote:
    > 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
     
    Paul Lalli, Nov 5, 2007
    #2
    1. Advertising

  3. Paul Lalli wrote:
    >
    > It's my birthday,


    Ooh, a Scorpio! Happy birthday Paul. Many happy returns.


    John
    --
    use Perl;
    program
    fulfillment
     
    John W. Krahn, Nov 5, 2007
    #3
  4. On 2007-11-05, John W. Krahn <> wrote:

    >> It's my birthday,

    >
    > Ooh, a Scorpio! Happy birthday Paul. Many happy returns.


    But not too many - leave something on his stack.

    --
    Elvis Notargiacomo master AT barefaced DOT cheek
    http://www.notatla.org.uk/goen/
     
    all mail refused, Nov 5, 2007
    #4
  5. Paul Lalli <> wrote:

    > It's my birthday,



    Those are good for you.

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

    ....

    ....

    .... live the longest.


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad McClellan, Nov 6, 2007
    #5
  6. Luca Villa

    Paul Lalli Guest

    On Nov 6, 6:56 am, Joe Smith <> wrote:
    > 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
     
    Paul Lalli, Nov 6, 2007
    #6
  7. Luca Villa

    Ted Zlatanov Guest

    On Tue, 06 Nov 2007 09:30:21 -0800 Jim Gibson <> wrote:

    JG> In article <>, Tad McClellan
    JG> <> wrote:

    >> Paul Lalli <> wrote:
    >>
    >> > It's my birthday,

    >>
    >>
    >> Those are good for you.
    >>
    >> A federally funded study has shown that people with the most birthdays...
    >>
    >> ...
    >>
    >> ...
    >>
    >> ... live the longest.


    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
     
    Ted Zlatanov, Nov 7, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Galt
    Replies:
    1
    Views:
    712
    zzyzx
    Jul 15, 2004
  2. Julia Briggs
    Replies:
    10
    Views:
    11,641
  3. Replies:
    2
    Views:
    343
    Roger Upole
    Dec 20, 2006
  4. Gibby Koldenhof
    Replies:
    4
    Views:
    305
    Gibby Koldenhof
    Jan 10, 2005
  5. Replies:
    0
    Views:
    309
Loading...

Share This Page