I am working with some .xml, and I have to extract part of them. I need to extract block between the line where appear >21120352</PMID> and the line where appears </PubmedArticle>
But the syntax of awk uses "/" so it gives me an error. I also have used the equivalent U+002F, but the solutions returns more than I want.
By the moment, I have this solution:
awk '/>21120352</,/PubmedArticle>/' file.xmlAlso I have used the wildcard:
awk '/>21120352<.PMID>/,/<.PubmedArticle>/' file.xmlMy question is if is possible to search using </PMID> and </PubmedArticle>
2 Answers
You need to escape the / with a backslash: \/.
awk '/>21120352<\/PMID>/,/<\/PubmedArticle>/' file.xmlAs an alternative to awk, I suggest to have a look at XMLStarlets xml sel function which is better in parsing XML files.
As an alternative to escaping the pattern using a backslash \ you can also use a variable to define your pattern:
awk '$0~pattern' pattern=">21120352</,/PubmedArticle>/" filename