Solved

perl finding a blank line

Posted on 2006-11-09
5
287 Views
Last Modified: 2006-11-18
I'm using a command to print out records from a file, there is a problem with some of the record that contain a blank line in them which
should not be there.

This command will print out all the records but I'm trying to modify it to print the the records only IF it contains a blank line in it.

perl -ne 'print if /^\S+:\s/../number of tasks=\d+/' file.txt


Thanks,


0
Comment
Question by:bt707
  • 3
  • 2
5 Comments
 

Author Comment

by:bt707
ID: 17905637
Example of one of the records that conain a blank line that should not be there.


CSmith: owner=csmith status=enabled
 name=Chris Smith
 description=
 
 other owners=
 double book=yes
 aces=@@o^a^r^g;@@o^c^wdeic^g;@^a^sf^g;@^c^^g;@^p^r^g
 email=
 time zone=
 categories=
 character set=
 language code=en
 created=Dec 21, 2003 05:50:20 GMT
 last modified=Dec 04, 2005 02:20:20 GMT
 events last modified=Dec 28, 2004 16:02:52 GMT
 todos last modified=Dec 28, 2004 16:02:52 GMT
 deletelog last modified=Dec 28, 2004 16:02:52 GMT
 number of events=500
 number of tasks=25

0
 
LVL 84

Expert Comment

by:ozo
ID: 17905884
How do we know the difference between a blank line in a record and a blank line separating two records?
0
 

Author Comment

by:bt707
ID: 17905902
ozo, in this file there is no blank lines any where (or there is not suppose to be that is) I have added blank lines before to the dump to make it more easy to
read and work with but the dump of these records normally come out all in one file and no blank lines anywhere. It's a file with 266K lines but does not contain any blank lines so I'm trying to pull out the records that are messed up and contain a blank line in them, and thats not so easy to find with the file being so long.

Thanks,
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 17906304
perl  -ne '/^\S+:\s/..(push @_,$_ and /number of tasks=\d+/ and (grep{/^\s*$/}@_ and print @_),@_=(),1)' file.txt
0
 

Author Comment

by:bt707
ID: 17906485
Thanks ozo, all I was getting was errors.

Worked perfect.

Thanks,
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

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…

808 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