Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-25
4
Medium Priority
?
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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

715 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