Solved

perl finding a blank line

Posted on 2006-11-09
5
296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

738 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