Afficher un message
Vieux 23/05/2007, 11h42   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to catch a block which contains some keywords with sed

2007-05-22, 23:42(-07), samuel:
[...]
> Now I need to analyze a file which is composed of several blocks ,
> which is defined as below :
>
> Start
> <content>
> <content>
> ......
> <content>
> End
>
>
>
> And I need to catch/print all the blocks which contains several
> specific keywords such "cpu" "dma" in the content part.
>
> Does any know to do this in sed or in other ways ?

[...]

It's not easy with sed and you may have size restrictions.
Easier with perl:

perl -0777 -ne'print for grep /cpu|dma/, (/^Start\n(.*?)^End$/mgs)'

Or

perl -0777 -ne'print for grep /cpu|dma/, (/^Start\n.*?^End\n/mgs)'

If you want to include the Start/End tags.

--
Stéphane
  Réponse avec citation
 
Page generated in 0,04393 seconds with 9 queries