Solved

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

Posted on 2011-03-25
4
255 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

752 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