perl -pe for blocks of lines instead of single lines

M

Markus Dehmann

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
 
T

Tad McClellan

Markus Dehmann said:
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.
 

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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top