Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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