perl -pe for blocks of lines instead of single lines

Discussion in 'Perl Misc' started by Markus Dehmann, Sep 26, 2006.

  1. I just found the answer to my own problem. I'm gonna share this so
    people can find it via google:

    I have a data file that contains blocks of data, separated by empty
    lines:

    line1
    line2

    line1
    line2

    Now I want to read it on the command line, one block at a time. But
    perl -pe '...' reads only single lines.

    The answer is: Use -00

    So, this:
    perl -00 -ne 'chomp; print "<BLOCK>$_</BLOCK>\n"' data.txt

    Prints
    <BLOCK>line 1
    line2</BLOCK>
    <BLOCK>line 1
    line2</BLOCK>

    Just wanted to share ...

    Markus
     
    Markus Dehmann, Sep 26, 2006
    #1
    1. Advertising

  2. Markus Dehmann <> wrote:

    > I just found the answer to my own problem.



    The perlrun.pod (how to execute the Perl interpreter) manpage
    contains the answer to your problem too.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Sep 26, 2006
    #2
    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. Arjen
    Replies:
    3
    Views:
    472
    Scott Allen
    Feb 27, 2005
  2. chris brat
    Replies:
    1
    Views:
    671
    chris brat
    May 10, 2006
  3. matt
    Replies:
    1
    Views:
    296
    George Ogata
    Aug 6, 2004
  4. Steven Taylor
    Replies:
    9
    Views:
    280
    Brian Candler
    Apr 27, 2009
  5. ela
    Replies:
    12
    Views:
    382
    Uri Guttman
    Apr 6, 2009
Loading...

Share This Page