Help with Pattern matching. Matching multiple lines from while reading from a file.

B

Bobby Chamness

Example from a file I'm reading.

2007-04-17 09:35:34 ACSSA[0]:
1431 N sa_demux.c 1 276
drive 4, 1, 1,11: Library error, Transport failure

I want to match the first and third line, that way I know the date and
drive info.

so the output on the print will look like this
2007-04-17 09:35:34 ACSSA[0]: drive 4, 1, 1,11: Library error, Transport
failure
 
M

Michele Dondi

Example from a file I'm reading.

2007-04-17 09:35:34 ACSSA[0]:
1431 N sa_demux.c 1 276
drive 4, 1, 1,11: Library error, Transport failure

All entries like this one? Separated by blank lines? Not separated?
I want to match the first and third line, that way I know the date and
drive info.

Depending on the answer to the questions above and the size of the
file, either slurp the file in and match over multiple lines or read
line by line and if match occurs read some more lines or if the
"format" is reliable enough do not match at all
so the output on the print will look like this
2007-04-17 09:35:34 ACSSA[0]: drive 4, 1, 1,11: Library error, Transport
failure

I'm still failing to see what you've tried thus far and how it doesn't
work for you. Under optimistic assumptions even the following oneliner
may work for you:

perl -lpe '<>;$_.=" ".<>'


Michele
 
X

Xicheng Jia

Example from a file I'm reading.

2007-04-17 09:35:34 ACSSA[0]:
1431 N sa_demux.c 1 276
drive 4, 1, 1,11: Library error, Transport failure

I want to match the first and third line, that way I know the date and
drive info.

so the output on the print will look like this
2007-04-17 09:35:34 ACSSA[0]: drive 4, 1, 1,11: Library error, Transport
failure

If all independent records are seperated by empty line, and you want
to remove the second line of all the three-line records, then

perl -00pe 's/\n.*\n/ /' file.txt

Regards,
Xicheng
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top