K
K
KiselevPD2019-08-28 21:10:32
XML
KiselevPD, 2019-08-28 21:10:32

How to cut everything from files except the desired tag?

Task: There are folders with files, in fact the files are xml. It is necessary to cut EVERYTHING from ALL these files in folders, except for one tag (*any value*).
Can you tell me how this process can be automated? There are already a lot of files there and it takes a long time to manually shovel them

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
vreitech, 2019-08-28
@fzfx

you can iterate through the files using find, for example. cut - grep, sed, awk.
I just don't understand what exactly "cut" means. give an example of what you have and what you want to get.

D
Dimonchik, 2019-08-28
@dimonchik2013

I recommend to master
https://www.regular-expressions.info/powergrep.html
you can buy on rutracker

Y
Yaroslav, 2019-08-29
@yaror

I would advise to look towards xmllint.
Unix utility, but Cygwin has it:
https://stackoverflow.com/questions/21871237/use-x...
An example format would be:
xmllint --xpath 'path-to-xml-tag' --output 'path -to-file-to-save-results' path-to-original-xml-file
For example, if you want to rip out all the tags, wherever they are, it would be something like this:
xmllint --xpath '//TaxNo' --output 'file.stripped.xml' file.xml
If you need to rip out not all TaxNo tags, but only those nested in the single Taxes tag, which, in turn, is nested in the Root root tag, then the command will be something like this:
xmllint --xpath ' /Root/Taxes//TaxNo' --output 'file.stripped.xml' file.xml

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question