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

x
?
Solved

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

Posted on 2011-02-16
3
Medium Priority
?
327 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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 …
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…
Six Sigma Control Plans

688 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