Hi Yoda I have one issue here I dont have abc as a static string.
I have a variable for this and if I have ' ' quotes then we are not able to pick the value of the variable
also I am a little new to Unix if possible can you please briefly explain the approach you have followed.
If you have string in variable, then assign it to an awk variable:
VAR="abc"
awk -v V="$VAR" ' # Assign V = "$VAR"
{
if ( $0 ~ ">" V "<" ) # If pattern ">" V "<" (>abc<) in current record.
f = 1 # If found, set f = 1
if ( f && $0 !~ ">" V "<" ) # If f == 1 and pattern ">" V "<" (>abc<) not in current record.
{
sub(/>.*</, ">4<") # Substitute everything with in >.*< by ">4<"
f = 0 # Reset f = 0
}
} 1 ' file
Hi Yoda I got that thanks
However I have one more issue I am using a command
sed s/$original/$new/g
in this case my new variable is like this
new=<a>123</a>\n<b>345</b>
I want the two xml tags to be in sep line and so I have inserted a \n
this is working fine in echo
however when I do the sed stuff I can see a n in the file itself.
Please let me know if we can actually add a new line