Solved

perl finding a blank line

Posted on 2006-11-09
5
259 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
perl  -ne '/^\S+:\s/..(push @_,$_ and /number of tasks=\d+/ and (grep{/^\s*$/}@_ and print @_),@_=(),1)' file.txt
0
 

Author Comment

by:bt707
Comment Utility
Thanks ozo, all I was getting was errors.

Worked perfect.

Thanks,
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now