[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Perl - Adding extra new lines

Posted on 2012-08-15
3
Medium Priority
?
481 Views
Last Modified: 2012-08-15
I have an issue where a file had to be rebuilt, there is sections in this file that is grouped together which is then separated by a blank line.

Right now I have the file where each section is separated by one blank line.

What I need to do is have each section to be separated by 3 blank lines.

Each sections starts with the same line as in the example below (just the date and time is different) but does not always end the same way.

How can I replace the one blank line with three blank lines between each section.

I've tried to replace the \n with 3 new lines but not coming out right.


Example of what is in the file, which the three sections below needs to be separated by 3 new lines rather than the one.

-------------------------------------------------
LDAP delete record being run at Fri 09-Aug-12 01:04:33
  (/opt/apache/directory.slb.com/delete-record.cgi)
  by cn=SAP LDAP Administrator  176785,ou=role,o=SLB,c=AN
     on 199.6.145.178,
  Deleting cn=John Doe  421214,ou=contractor,O=abc,C=AN
               cn:John Doe
                 Joseph Lo Gerald  638295
            alias:Jdoe
               id:421214
              uid:jdoe-20110715
   employeenumber:038457444
                c:MY
         comments:Delete by SAP
  cn=John Doe  421214,ou=contractor,O=SLB,C=AN deleted

LDAP delete record being run at Fri 10-Aug-12 00:07:88
  (/opt/apache/directory.slb.com/delete-record.cgi)
  by cn=SAP LDAP Administrator  176785,ou=role,o=SLB,c=AN
     on 199.6.145.178,
  Deleting cn=John Doe  421214,ou=contractor,O=abc,C=AN
               cn:John Doe
                 Joseph Lo Gerald  638295
            alias:Jdoe
               id:421214
              uid:jdoe-20110715
   employeenumber:038457444
                c:MY
         comments:Delete by SAP
  cn=John Doe  421214,ou=contractor,O=SLB,C=AN deleted

LDAP delete record being run at Fri 10-Aug-12 01:04:33
  (/opt/apache/directory.slb.com/delete-record.cgi)
  by cn=SAP LDAP Administrator  176785,ou=role,o=SLB,c=AN
     on 199.6.145.178,
  Deleting cn=John Doe  421214,ou=contractor,O=abc,C=AN
               cn:John Doe
                 Joseph Lo Gerald  638295
            alias:Jdoe
               id:421214
              uid:jdoe-20110715
   employeenumber:038457444
                c:MY
         comments:Delete by SAP
  cn=John Doe  421214,ou=contractor,O=SLB,C=AN deleted


Thanks for any help
0
Comment
Question by:bt707
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 38295953
Try:

perl -p -e 's/^\s*$\n/\n\n\n/g' input_file > output_file

Open in new window

0
 

Author Comment

by:bt707
ID: 38296010
That is not working, still gives me the same thing where all sections is separated by one line.

Also I cannot do it that way as there is sometimes a blank line in the middle of a section, so need to use the first line as I showed above and replace that with 3 blank lines before each of the sections by using the first line.
0
 

Author Closing Comment

by:bt707
ID: 38296034
That did not do it but gave me an idea I've used before and I got it working with:

perl -p -e 's/^(LDAP delete record being run.*$)/\n\n\n$1/'

Thanks for you help, I got what I needed to work.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
Six Sigma Control Plans
Suggested Courses

873 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