|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi ,
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 ? Thanks in advance ! Samuel |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
samuel wrote:
> Hi , > > 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 ? Do you mean contains one of the keywords or contains some combination of the keywords or contains all of the keywords or something else? > Thanks in advance ! > > Samuel > Try this to start with: awk ' /Start/ { inBlock=1; block="" } inBlock { block=block $0 ORS; if (/cpu|dma/) inBlock=2 } /End/ { if (inBlock==2) printf "%s",block; inBlock=0 } ' file then clarify your requirements if necessary. Ed. |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On May 23, 2:42 am, samuel <samuelz...@gmail.com> wrote:
> Hi , > > 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 ? > > Thanks in advance ! > > Samuel Does sed '/cpu/!d; /dma/!d' filename not work for this... |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On May 25, 12:10 am, sil <dsphunx...@gmail.com> wrote:
> On May 23, 2:42 am, samuel <samuelz...@gmail.com> wrote: > > > > > > > Hi , > > > 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 ? > > > Thanks in advance ! > > > Samuel > > Does sed '/cpu/!d; /dma/!d' filename not work for this...- Hide quoted text - > > - Show quoted text - Thanks Ed and all, 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)' did works in this case. Rgds, Samuel |
|
![]() |
| Outils de la discussion | |
|
|