I have the following xml:
<Flusso cod_flusso="abc">
<Identificativi>
<piva_1>000000</piva_1>
<piva_2>111111</piva_2>
</Identificativi>
<Dati>
<cod>001100000111111</cod>
<mese>01/2021</mese>
<DatiTecn>
<Tratt>G</Tratt>
<coeff>1.0</coeff>
<Racc>P</Racc>
<esito>P</esito>
</DatiTecn>
<Letture>
<matr>MIT00000000000000</matr>
<data>01/01/2021</data>
<tipo>E</tipo>
<let>000003101</let>
</Letture>
<Letture>
<matr>MIT00000000000000</matr>
<data>02/01/2021</data>
<tipo>E</tipo>
<let>000003104</let>
</Letture>
<Letture>
<matr>MIT00000000000000</matr>
<data>03/01/2021</data>
<tipo>E</tipo>
<let>000003106</let>
</Letture>
</Dati>
</Flusso>
how can join cod value with data value using sed, awk or xmllint in bash unix and obtain the csv output:
001100000111111;01/01/2021 001100000111111;02/01/2021 001100000111111;03/01/2021
for the example this works, not sure what most general case is...
$ xmllint --xpath '//cod | //cod/following-sibling::*/data' file |
awk -F'[><]' 'NR==1{cod=$3; next} {printf "%s;%s ",cod,$3} END{print ""}'
001100000111111;01/01/2021 001100000111111;02/01/2021 001100000111111;03/01/2021
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.