Afficher un message
Vieux 31/10/2007, 03h39   #7
John W. Krahn
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Combine multiple line segment into one, when certain pattern isfound - awk/sed/perl

"da. Ram" wrote:
>
> Dear Group,
>
> I have a file with the content in the following format:
>
> Junk...
> Junk...
>
> Heading P01
> column1 column2 multiline text
> CA1001 10 This is a multiline
> text spanning two lines
>
> CA1005 12 This is a multiline
> text spanning three
> lines
>
> CA1008 11 This is a single line text
>
> Heading P02
> column1 column2
> CA2001 10
> CA2003 11
> CA2005 12
>
> Heading P03
> Junk..
> Junk..
>
> I would like to list all the values under "Heading P01" for the same
> column1 in a single line
>
> CA1001 10 This is a multiline text spanning two lines
> CA1005 12 This is a multiline text spanning three lines
> CA1008 11 This is a single line text
>
> Note: The column1 values will always have "CA" as the starting
> character.
>
> Appreciate your in finding a solution using awk or perl or
> sed ...


$ echo "Junk...
Junk...

Heading P01
column1 column2 multiline text
CA1001 10 This is a multiline
text spanning two lines

CA1005 12 This is a multiline
text spanning three
lines

CA1008 11 This is a single line text

Heading P02
column1 column2
CA2001 10
CA2003 11
CA2005 12

Heading P03
Junk..
Junk..
" | perl -ln00e's/^.+\n(?=CA)//s,y/\n//d,print,if/Heading P01/../Heading
P02/and!/Heading P02/'
CA1001 10 This is a multiline text spanning two lines
CA1005 12 This is a multiline text spanning three lines
CA1008 11 This is a single line text




John
--
use Perl;
program
fulfillment
  Réponse avec citation
 
Page generated in 0,05240 seconds with 9 queries