Solved

perl finding a blank line

Posted on 2006-11-09
5
278 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl program to obtain a machine's memory usage 6 22
perl script to count sepecial characters in a file 7 146
Perl strange behaviour 5 72
perl split by | 2 97
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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

770 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