Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

perl finding a blank line

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
bt707
Asked:
bt707
  • 3
  • 2
1 Solution
 
bt707Author Commented:
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
 
ozoCommented:
How do we know the difference between a blank line in a record and a blank line separating two records?
0
 
bt707Author Commented:
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
 
ozoCommented:
perl  -ne '/^\S+:\s/..(push @_,$_ and /number of tasks=\d+/ and (grep{/^\s*$/}@_ and print @_),@_=(),1)' file.txt
0
 
bt707Author Commented:
Thanks ozo, all I was getting was errors.

Worked perfect.

Thanks,
0

Featured Post

Industry Leaders: 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!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now