?
Solved

Need a simple PERL script to remove blank lines from txt file

Posted on 2006-05-06
4
Medium Priority
?
205 Views
Last Modified: 2006-11-18
I need a  perl script that will iterate through a txt file and REMOVE any lines that match this regex: m/\A(?:^\|.\|..\|.+$)\z/m)
An example of a line the regex is to match is: "| |  | +--ActiveX" (in case my regex isn't ideal).
The name of the txt file can be hard coded, as it will not change (don't need to prompt for it). It will be "tree.txt".
Lastly, I would rather have a few more lines of code in order for the script to be easily understood, as this is more important to me than brevity.
Thank you.
0
Comment
Question by:lessthan2
  • 2
  • 2
4 Comments
 
LVL 4

Expert Comment

by:ps15
ID: 16622973
m/\A(?:^\|.\|..\|.\+$)\z/m

you probably want to escape the +

perl -ne "print unless m/\A(?:^\|.\|..\|.\+$)\z/m"  infile > outfile
0
 

Author Comment

by:lessthan2
ID: 16623107
Thanks ps15.  It's removing the correct lines, but it's not then removing the blank lines.  Do you think we need to do a second run through the file to remove the blank lines?
0
 
LVL 4

Accepted Solution

by:
ps15 earned 1200 total points
ID: 16623258
perl -ne "print unless (m/\A(?:^\|.\|..\|.\+$)\z/m or /^[\s\n\r]+$/)"  infile > outfile
0
 

Author Comment

by:lessthan2
ID: 16623280
Excellent!  Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question