I have a file with below data.Lets call it as myfile.xml
:
.........
<header>unique_name</header>
......
somelines
......
<version>I need only this line</version>
......
......
<version>This is second match of version, which I dont want</version>
Now I'm in search of linux commands that does below things:
There can be many
<header>.*</header>
lines. But I need<header>unique_name</header>
.This is an unique header name that I will hardcore it.It appears only once in the file, but can appear anywhere in the file.Search for
<version>.*</version>
that appears after<header>unique_name</header>
in myfile.txt and this should be replaced with<version>new version number</version>
.
I've tried implementing using grep
, sed
, awk
, but I could not. Please advise.
Input and Expected Output:
Input file "myfile.xml":
- stringtoFIND=
<header>unique_name</header>
- newversionNUMBER=new_version_number
The myfile.xml
file contents below:
<header>Some strings</header>
......Somelines...........
<version>I dont need this line, since header doesnt match stringtoFIND variable</version>
<header>unique_name</header>
.............
<version>I need only this line</version>
...........
..........
<version>I Dont need this line</version>
.........
Expected output
<header>Some strings</header>
......Somelines...........
<version>I dont need this line, since header doesnt match stringtoFIND variable</version>
<header>unique_name</header>
.............
<version>new_version_number</version>
...........
..........
<version>I Dont need this line</version>
.........