Solved

Add a marker to the first row of a record using Perl

Posted on 2011-02-16
3
320 Views
Last Modified: 2012-05-11
I have this data record using a input record separator as __Data__ and would like to add a marker to the first row of this data record.

Current,

Here's the data record....

__Data__
scsi_test_hotswap
stop
Passed
1. dldldld - dldldldldldldldld
2. dldldld - dldldldldlldldldld
1. dldldld - dldldldldldldldld
2. dldldld - dldldldldlldldldld

__Data__
scsi_test_memory_leakage
stop
Passed
1. dldldld - dldldldldldldldld
2. dldldld - dldldldldlldldldld
3. dldldld - dldldldldldldldld
4. dldldld - dldldldldlldldldld

Ideal output would be

Here's the data record....

__Data__
@scsi_test_hotswap
stop
Passed
1. dldldld - dldldldldldldldld
2. dldldld - dldldldldlldldldld
1. dldldld - dldldldldldldldld
2. dldldld - dldldldldlldldldld

__Data__
@scsi_test_memory_leakage
stop
Passed
1. dldldld - dldldldldldldldld
2. dldldld - dldldldldlldldldld
3. dldldld - dldldldldldldldld
4. dldldld - dldldldldlldldldld

I know the solution would be to use a regex search and replace but not sure how to construct it....
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
3 Comments
 
LVL 16

Accepted Solution

by:
sjklein42 earned 500 total points
ID: 34912083
save as fixit.pl

perl fixit.pl infile.txt >outfile.txt

$fixNext = 0;
while ( <> )
{
	s/[\r\n]//g;
	if ( $fixNext ) { $_ = '@' . $_; $fixNext = 0; }
	if ( /__Data__/ ) { $fixNext = 1; }
	print $_ . "\n";
}

Open in new window

0
 

Author Comment

by:areyouready344
ID: 34912113
worked perfect, thanks sjklein42.....
0
 

Author Closing Comment

by:areyouready344
ID: 34912116
excellent solution...
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

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

751 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