Solved

how to mark a certain line in a multiline data record?

Posted on 2011-03-25
4
225 Views
Last Modified: 2012-05-11
I need to mark the start of a line with a # sign following the above line with the name of the Operating System in a multiline data record.

For example,

__Data__
@test_scsi  
(memory test)
windows (xp)
#dklldkdslsjkflskfljsklfjklsjfklsjkflsjklfs


What I don't want is to put a #sign on any lines if a line contains any number lines following the above line of the Operating System.

For example, this data record contains a number line so no # sign is needed.

__Data__
@test_scsi  
(memory test)
windows (xp)
1. dklldkdslsjkflskfljsklfjklsjfklsjkflsjklfs
djkfkdljkfldsjkfljsklfjls

The problem with my code below is that it puts a # sign even if the line following the Operating line contains a number line.

For example, the code below puts a #sign even when the data record contains a number line

__Data__
@test_scsi  
(memory test)
windows (xp)
1. dklldkdslsjkflskfljsklfjklsjfklsjkflsjklfs
#fkkfkfkfkfkfkf

#!/usr/bin/perl

use strict;
use warnings;

$/='__Data__';

my $os = '(?:windows|linux|mac)';
open 'FH','<',"/home/data_record";

while (<FH>)
{
          $_ =~ s/(^\@[^\n]*)(.*?)(^$os[^\n]*)(.*?)(^[a-zA-Z][^\n]*$)(.*?)/$1$2$3$4#$5$6/ms;
            print;
}
0
Comment
Question by:areyouready344
  • 2
4 Comments
 
LVL 4

Expert Comment

by:dagesi
ID: 35216172
Within the grouping for $5, have you tried adding a (^\d) - the intent to say that it isn't starting with a number?
0
 
LVL 4

Expert Comment

by:dagesi
ID: 35216195
Or I guess that would actually be \D , wouldn't it?
0
 
LVL 26

Accepted Solution

by:
wilcoxon earned 500 total points
ID: 35216260
This should do it...
#!/usr/bin/perl

use strict;
use warnings;

$/='__Data__';

my $os = '(?:windows|linux|mac)';
open FH, '<', '/home/data_record' or die "could not open data_record: $!";

while (<FH>) {
    s{^(\@.*\n$os[^\n]+\n)(?!\d)}{$1#}ms;
    print;
}

Open in new window

0
 

Author Comment

by:areyouready344
ID: 35216452
Thanks Wilcoxon, I can not find no problems with your code. In other words, its working solid.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
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…

760 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

17 Experts available now in Live!

Get 1:1 Help Now