Solved

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

Posted on 2011-03-25
4
260 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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…
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

627 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