Extract lines between tags and conditions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract lines between tags and conditions
# 1  
Old 01-17-2013
Extract lines between tags and conditions

Hi forum,
I need help .. I need to extract from the log file logfile.log all the rows between the tags "<SOAP-ENV: Envelope" "</ SOAP-ENV: Envelope>" and that contain a certain <idPrescrizione> 0FXTN091GI </ idPrescrizione>.

Within logfile.log there could be more 'occurrences of the same

Some more 'experienced than me' with awk or sed could direct me on how to do?


Tnk
Pier


logfile.log

Code:
        <idModulo>030061211118838</idModulo>
              <dataPrenotazione>20130116082914</dataPrenotazione>
              <memorandum/>
              <memorandumLink/>
              <noteDisdettaPrenotazione/>
              <noteDisdettaPrenotazioneLink/>
              <consensoInformatoLink/>
                        </appuntamento>
                    </listaAppuntamenti>
            </dati>
        </m:GP.registraAppuntamenti>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

20130116 08:29:15:820:BONES:TRACE:httpWorkerThread-10080-0;SissDCMDBBean  RESPONSE <?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"><SOAP-ENV:Body><m:GP.registraAppuntamentiResponse xmlns:m="http://www.crs.veneto.it/schemas/DCSanita/GP/2011-01/registraAppuntamenti/"><esitoRegistraAppuntamenti><messaggio>OK</messaggio></esitoRegistraAppuntamenti></m:GP.registraAppuntamentiResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
20130116 08:29:16:36:BONES:TRACE:httpWorkerThread-10080-0;SissErrorMDBBean onMessage() - ENTER -
20130116 08:29:43:815:BONES:TRACE:httpWorkerThread-10080-0;SissErrorMDBBean onMessage() - ENTER -
20130116 08:29:45:950:BONES:TRACE:httpWorkerThread-10080-0;SissErrorMDBBean onMessage() - ENTER -
20130116 08:30:03:185:BONES:TRACE:httpWorkerThread-10080-0;SissErrorMDBBean onMessage() - ENTER -
20130116 08:30:03:213:BONES:TRACE:httpWorkerThread-10080-0;SissDCMDBBean  MESSAGGIO DELLA CODA <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding">
     <SOAP-ENV:Body>
        <m:GP.registraAppuntamenti xmlns:m="http://www.crs.veneto.it/schemas/DCSanita/GP/2011-01/registraAppuntamenti/" track="R">                             
            <dati>
                    <datiCittadino>
                           <numeroTelefono>04848685</numeroTelefono>
                           <sms/>
                           <indirizzoEmail/>
                    </datiCittadino>
                    <listaAppuntamenti>
                        <appuntamento>
                            <idPrescrizione>054HN0L9OV</idPrescrizione>
                            <idRichiestaPrenotazione/>
                            <idPrestazioneSiss>088952</idPrestazioneSiss>
                            <dataAppuntamento>20130416090000</dataAppuntamento>
                            <stato>0</stato>
                            <idInterno>13B000028775</idInterno>
                            <idPrestazioneInterno>OCARROLLA</idPrestazioneInterno>
                            <notePreparazione/>
                            <operatoreRichiedente>CNDGRL76M44G371U</operatoreRichiedente>
                            <ruoloOperatoreRichiedente>23</ruoloOperatoreRichiedente>
                            <idUnitaErogatriceOperatoreRichiedente/>
                            <idStrutturaOperatoreRichiedente/>
                            <idRepartoOperatoreRichiedente/>
                            <idUnitaPrenotante>26</idUnitaPrenotante>
                            <regimeErogazione>1</regimeErogazione>
                            <idUnitaErogatrice>1553</idUnitaErogatrice>
                            <idStruttura>030978</idStruttura>
                            <tipoAppuntamento/>
                            <descrizionePrestazione/>
                            <descrizioneUP/>
                            <descrizioneUE/>
                            <descrizioneAgendaInterna>AMBULATORIO CARDIOLOGICO _DR.ROLLA</descrizioneAgendaInterna>
                            <descrizioneStruttura/>
                            <noteAppuntamento/>
                            <dsLuogoPresentazione>1^PIANO - STANZA N. 12</dsLuogoPresentazione>
                            <noteAppuntamentoOperatoreSISS/>
                            <tmaSsn/>
                            <primaDataProposta>20130416090053</primaDataProposta>
                            <idProgressivoAppuntamentoCombinato/>
                            <idModulo>030101038898067</idModulo>
              <dataPrenotazione>20130116083003</dataPrenotazione>
              <memorandum/>
              <memorandumLink/>
              <noteDisdettaPrenotazione/>
              <noteDisdettaPrenotazioneLink/>
              <consensoInformatoLink/>
                        </appuntamento>
                    </listaAppuntamenti>
            </dati>
        </m:GP.registraAppuntamenti>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

20130116 08:30:03:939:BONES:TRACE:httpWorkerThread-10080-0;SissDCMDBBean  RESPONSE <?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"><SOAP-ENV:Body><m:GP.registraAppuntamentiResponse xmlns:m="http://www.crs.veneto.it/schemas/DCSanita/GP/2011-01/registraAppuntamenti/"><esitoRegistraAppuntamenti><esitoNegativo><codiceErrore>SEBC00001</codiceErrore><descErrore>esito negativo della transazione</descErrore><listaEccezioni><eccezione><nomeCampo>Cittadino non trovato</nomeCampo><codiceEccezioneCampo>ED0111</codiceEccezioneCampo><descEccezioneCampo>Cittadino non presente in anagrafe</descEccezioneCampo><descEccezione>Dato input non valido</descEccezione><ROI/><codiceEccezione>EA0004</codiceEccezione></eccezione></listaEccezioni></esitoNegativo></esitoRegistraAppuntamenti></m:GP.registraAppuntamentiResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
20130116 08:30:04:173:BONES:TRACE:httpWorkerThread-10080-0;SissErrorMDBBean onMessage() - ENTER -
20130116 08:30:04:174:BONES:TRACE:httpWorkerThread-10080-0;SissErrorMDBBean onMessage() - ENTER -
20130116 08:30:54:927:BONES:TRACE:httpWorkerThread-10080-0;SissErrorMDBBean onMessage() - ENTER -
20130116 08:30:54:949:BONES:TRACE:httpWorkerThread-10080-0;SissDCMDBBean  MESSAGGIO DELLA CODA <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding">
     <SOAP-ENV:Body>
      <m:GP.annullaAppuntamentiDaCUP xmlns:m="http://www.crs.veneto.it/schemas/DCSanita/GP/2009-01/annullaAppuntamentiDaCUP/" dataSetVersion="1.0" track="R">
         <appuntamento>

20130116 08:33:38:431:BONES:TRACE:httpWorkerThread-10080-1;SissDCMDBBean  MESSAGGIO DELLA CODA <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding">
     <SOAP-ENV:Body>
        <m:GP.registraAppuntamenti xmlns:m="http://www.crs.sicilia.it/schemas/DCSanita/GP/2011-01/registraAppuntamenti/" track="R">                             
            <dati>
                    <datiCittadino>
                           <numeroTelefono>038456494</numeroTelefono>
                           <sms/>
                           <indirizzoEmail/>
                    </datiCittadino>
                    <listaAppuntamenti>
                        <appuntamento>
                            <idPrescrizione/>
                            <idRichiestaPrenotazione>R2APDC33</idRichiestaPrenotazione>
                            <idPrestazioneSiss>438901.47</idPrestazioneSiss>
                            <dataAppuntamento>20130220113000</dataAppuntamento>
                            <stato>0</stato>
                            <idInterno>13B000031281</idInterno>
                            <idPrestazioneInterno>432PLPAV</idPrestazioneInterno>
                            <notePreparazione/>
                            <operatoreRichiedente>GRahsui351Q</operatoreRichiedente>
                            <ruoloOperatoreRichiedente>23</ruoloOperatoreRichiedente>
                            <idUnitaErogatriceOperatoreRichiedente/>
                            <idStrutturaOperatoreRichiedente/>
                            <idRepartoOperatoreRichiedente/>
                            <idUnitaPrenotante>5</idUnitaPrenotante>
                            <regimeErogazione>1</regimeErogazione>
                            <idUnitaErogatrice>1502</idUnitaErogatrice>
                            <idStruttura>030979</idStruttura>
                            <tipoAppuntamento/>
                            <descrizionePrestazione/>
                            <descrizioneUP/>
                            <descrizioneUE/>
                            <descrizioneAgendaInterna>(N) UROLOGIA </descrizioneAgendaInterna>
                            <descrizioneStruttura/>
                            <noteAppuntamento/>
                            <dsLuogoPresentazione/>
                            <noteAppuntamentoOperatoreSISS/>
                            <tmaSsn/>
                            <primaDataProposta>20130220113033</primaDataProposta>
                            <idProgressivoAppuntamentoCombinato/>
                            <idModulo>030120504331198</idModulo>
              <dataPrenotazione>20130116083338</dataPrenotazione>
              <memorandum/>
              <memorandumLink/>
              <noteDisdettaPrenotazione/>
              <noteDisdettaPrenotazioneLink/>
              <consensoInformatoLink/>
                        </appuntamento>
                    </listaAppuntamenti>
            </dati>
        </m:GP.registraAppuntamenti>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

20130116 08:33:39:691:BONES:TRACE:httpWorkerThread-10080-1;SissDCMDBBean  RESPONSE <?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"><SOAP-ENV:Body><m:GP.registraAppuntam






the expected result should be this:

result.txt

Code:
20130116 08:30:03:213:BONES:TRACE:httpWorkerThread-10080-0;SissDCMDBBean  MESSAGGIO DELLA CODA <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding" xmlns:xsd="http://www.w3.org/1999/XMLSchema" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding">
     <SOAP-ENV:Body>
        <m:GP.registraAppuntamenti xmlns:m="http://www.crs.veneto.it/schemas/DCSanita/GP/2011-01/registraAppuntamenti/" track="R">                             
            <dati>
                    <datiCittadino>
                           <numeroTelefono>04848685</numeroTelefono>
                           <sms/>
                           <indirizzoEmail/>
                    </datiCittadino>
                    <listaAppuntamenti>
                        <appuntamento>
                            <idPrescrizione>054HN0L9OV</idPrescrizione>
                            <idRichiestaPrenotazione/>
                            <idPrestazioneSiss>088952</idPrestazioneSiss>
                            <dataAppuntamento>20130416090000</dataAppuntamento>
                            <stato>0</stato>
                            <idInterno>13B000028775</idInterno>
                            <idPrestazioneInterno>OCARROLLA</idPrestazioneInterno>
                            <notePreparazione/>
                            <operatoreRichiedente>CNDGRL76M44G371U</operatoreRichiedente>
                            <ruoloOperatoreRichiedente>23</ruoloOperatoreRichiedente>
                            <idUnitaErogatriceOperatoreRichiedente/>
                            <idStrutturaOperatoreRichiedente/>
                            <idRepartoOperatoreRichiedente/>
                            <idUnitaPrenotante>26</idUnitaPrenotante>
                            <regimeErogazione>1</regimeErogazione>
                            <idUnitaErogatrice>1553</idUnitaErogatrice>
                            <idStruttura>030978</idStruttura>
                            <tipoAppuntamento/>
                            <descrizionePrestazione/>
                            <descrizioneUP/>
                            <descrizioneUE/>
                            <descrizioneAgendaInterna>AMBULATORIO CARDIOLOGICO _DR.ROLLA</descrizioneAgendaInterna>
                            <descrizioneStruttura/>
                            <noteAppuntamento/>
                            <dsLuogoPresentazione>1^PIANO - STANZA N. 12</dsLuogoPresentazione>
                            <noteAppuntamentoOperatoreSISS/>
                            <tmaSsn/>
                            <primaDataProposta>20130416090053</primaDataProposta>
                            <idProgressivoAppuntamentoCombinato/>
                            <idModulo>030101038898067</idModulo>
              <dataPrenotazione>20130116083003</dataPrenotazione>
              <memorandum/>
              <memorandumLink/>
              <noteDisdettaPrenotazione/>
              <noteDisdettaPrenotazioneLink/>
              <consensoInformatoLink/>
                        </appuntamento>
                    </listaAppuntamenti>
            </dati>
        </m:GP.registraAppuntamenti>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>


Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.
# 2  
Old 01-17-2013
The sample above seems to contain sensitive data, you may try to obfuscate it (phone numbers, descrizione agenda interna etc.).
# 3  
Old 01-17-2013
of course, are already clouded!
# 4  
Old 01-17-2013
You may try something like this:

Code:
awk '/<SOAP-ENV:Envelope/, /<\/SOAP-ENV:Envelope>/ {  
  r = length(r) ? r ORS $0 : $0  
  if (/<\/SOAP-ENV:Envelope>/) {
    if (r ~ "<idPrescrizione>" p "<\\/idPrescrizione")
      print r
    r = x
    }
  }' p=0FXTN091GI infile

Note that there are more appropriate tools than awk and sed for parsing xml data.
Please note also that I've modified the patterns to match the sample above.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to print lines that meet conditions and have value in another file

I am trying to use awk to print lines that satisfy either of the two conditions below: condition 1: $2 equals CNV and the split of $3, the value in red, is greater than or equal to 4. ---- this is a or so I think condition 2: $2 equals CNV and the split of $3, the value in red --- this is a... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Extract duplicate rows with conditions

Gents Can you help please. Input file 5490921425 1 7 1310342 54909214251 5490921425 2 1 1 54909214252 5491120937 1 1 3 54911209371 5491120937 3 1 1 54911209373 5491320785 1 ... (4 Replies)
Discussion started by: jiam912
4 Replies

3. UNIX for Dummies Questions & Answers

Shell script to extract data from csv file based on certain conditions

Hi Guys, I am new to shell script.I need your help to write a shell script. I need to write a shell script to extract data from a .csv file where columns are ',' separated. The file has 5 columns having values say column 1,column 2.....column 5 as below along with their valuesm.... (1 Reply)
Discussion started by: Vivekit82
1 Replies

4. UNIX for Dummies Questions & Answers

awk - Extract 4 lines in Column to Rows Tab Delimited between tags

I have tried the following to no avail. xargs -n8 < test.txt awk '{if(NR%6!=0){p=""}else{p="\n"};printf $0" "p}' Mod_Alm_log.txt > test.txt I have tried different variations of the above, the problem is mixes lines together. And it includes the tags "%a and %A" I need them to be all tab... (16 Replies)
Discussion started by: mytouchsr
16 Replies

5. Shell Programming and Scripting

Search for a pattern,extract value(s) from next line, extract lines having those extracted value(s)

I have hundreds of files to process. In each file I need to look for a pattern then extract value(s) from next line and then search for value(s) selected from point (2) in the same file at a specific position. HEADER ELECTRON TRANSPORT 18-MAR-98 1A7V TITLE CYTOCHROME... (7 Replies)
Discussion started by: AshwaniSharma09
7 Replies

6. Shell Programming and Scripting

Extract paragraphs under conditions

Hi all, I want to extract some paragraphs out of a file under certain conditions. - The paragraph must start with 'fmri' - The paragraph must contain the string 'restarter svc:/system/svc/restarter:default' My input is like that : fmri svc:/system/vxpbx:default state_time Wed... (4 Replies)
Discussion started by: Armoric
4 Replies

7. UNIX for Dummies Questions & Answers

Cutting lines if conditions are met

Hi. I am not sure how to solve this problem and if it is possible to do so with scripting. :wall: Let's say I have this data: A 12345 12360 A 12359 12380 A 12381 12390 A 12400 12450 A 12451 12460 B 23456 23460 B 23470 23480 B 23477 23505 I wan't each line to be compared in this... (5 Replies)
Discussion started by: danieladna
5 Replies

8. Shell Programming and Scripting

How to extract lines between tags into different files?

I have an xml file with the below data: unix>Cat address.xml <Address City=”Amsterdam” Street = “station straat” ZIPCODE="2516 CK " </Address> <Address City=”Amsterdam” Street = “Leeuwen straat” ZIPCODE="2517 AB " </Address> <Address City=”The Hauge” Street = “kirk straat” ... (1 Reply)
Discussion started by: LinuxLearner
1 Replies

9. Shell Programming and Scripting

Extract file records based on some field conditions

Hello Friends, I have a file(InputFile.csv) with the following columns(the columns are pipe-delimited): ColA|ColB|ColC|ColD|ColE|ColF Now for this file, I have to get those records which fulfil the following condition: If "ColB" is NOT NULL and "ColD" has values one of the following... (9 Replies)
Discussion started by: mehimadri
9 Replies

10. Shell Programming and Scripting

extract lines based on few conditions

Hi, I need to extract lines based on some conditions as explained below: File format details: notes: 1. each set starts with AAA only 2. number of columns is fixed 3. number of rows per set may vary (as one set is upto DDD - 4 rows) Now, if any BBB's 5th column is blank then then... (4 Replies)
Discussion started by: prvnrk
4 Replies
Login or Register to Ask a Question