I'm looking to iterate through a list of ID numbers which matches ID numbers in an XML file and print the line below using BASH (and AWK) to the shell or redirect it to a third, output file (output.txt)
Here is the breakdown:
ID_list.txt (shortened for this example - it has 100 IDs)
4414
4561
2132
999
1231
34
489
3213
7941
XML_example.txt (thousands of entries)
<book>
<ID>4414</ID>
<name>Name of first book</name>
</book>
<book>
<ID>4561</ID>
<name>Name of second book</name>
</book>
I'd like the output of the script to be the names of the 100 IDs from the first file:
Name of first book
Name of second book
etc
I believe it's possible to do this using BASH and AWK with a for loop (for each in file 1, find the corresponding name in file2). I think you can recurisvely GREP for the ID number and then print the line below it using AWK. Even if the output looked like this, I can remove the XML tags after:
<name>Name of first book</name>
<name>Name of second book</name>
It's on a Linux server but I can port it over to PowerShell on Windows. I think BASH/GREP and AWK are the way to go.
Can someone help me script this?
awkis not the right choice for parsing XML. - chepnerBASH_REMATCH, though still obviously simpler in a language that includes a package to do it for you. - Reinstate Monica Please