Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > perl -pe for blocks of lines instead of single lines

Reply
Thread Tools

perl -pe for blocks of lines instead of single lines

 
 
Markus Dehmann
Guest
Posts: n/a
 
      09-26-2006
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

 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      09-26-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
resolve single line with multiple items into mutliple lines, single items ela Perl Misc 12 04-06-2009 06:47 PM
Custom Taglib problems - instead of a single instance per page, I have a single instance per application. chris brat Java 1 05-10-2006 11:16 AM
"Building Blocks" are "Application Blocks" Arjen ASP .Net 3 02-27-2005 01:06 AM
procs/blocks - blocks with procs, blocks with blocks? matt Ruby 1 08-06-2004 01:33 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57