Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Help with Pattern matching. Matching multiple lines from while reading from a file. (http://www.velocityreviews.com/forums/t902925-help-with-pattern-matching-matching-multiple-lines-from-while-reading-from-a-file.html)

Bobby Chamness 05-03-2007 03:37 AM

Help with Pattern matching. Matching multiple lines from while reading from a file.
 
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



Michele Dondi 05-03-2007 08:31 AM

Re: Help with Pattern matching. Matching multiple lines from while reading from a file.
 
On Wed, 2 May 2007 22:37:33 -0500, "Bobby Chamness"
<b_chamness@comcast.net> wrote:

>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
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,

Xicheng Jia 05-03-2007 06:02 PM

Re: Help with Pattern matching. Matching multiple lines from while reading from a file.
 
On May 2, 11:37 pm, "Bobby Chamness" <b_chamn...@comcast.net> wrote:
> 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



All times are GMT. The time now is 07:38 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.