jrfiol
1
I am new, really new to bash scripts.
I want to search an XML file for a certain string, say "1234567890"
Once found, I want to copy the entire contents from the previous instance of the string "Entity" to the next instance of "/Entity" to a txt file.
And then continue searching for the string in the same file.
Thank you for any guidance,
jrfiol
What's your system?
With some versions of awk/nawk you can do this:
$ echo "<entity><slartibartfast>1234567890</slartibartfast></entity><entity><slood>abcd</slood></entity>" |
awk -v RS="<entity" -v FS="<" '/1234567890/ && ($NF == "/entity>") { print RS $0 }'
<entity><slartibartfast>1234567890</slartibartfast></entity>
$
1 Like
CarloM
4
RHEL uses GNU awk, so Corona's example should work.
jrfiol
5
Thanks for the reply, i have been able to get the awk command to get the value i was looking for. thaks!