I have an xml file which looks like below
INPUT XML FILE
<ReconSummary>
<entryName>Total Deep</entryName>
<Code>777</Code>
<License>L</License>
<Tran>H20</Tran>
<job>1234</job>
</ReconSummary>
<ReconSummary>
<entryName>Total Saurav</entryName>
<Code>666</Code>
<License>L</License>
<Tran>H20</Tran>
<job>1234</job>
</ReconSummary>
<ReconSummary>
<entryName>Total Ankur</entryName>
<Code>555</Code>
<License>L</License>
<Tran>H20</Tran>
<job>1234</job>
</ReconSummary>
I was trying to search the pattern "Total Deep" and after that i want to comment out the the tag after 3rd or 4th line of the matching pattern in xml file
My code is below
while read -r line do;
LineNum=`grep -n "Total Deep" input.xml | cut -d: -f 1`
TOTAL=`expr $LineNum + 4`
echo $LineNum
echo $TOTAL
done < file.txt
While executing the code i am getting below exception
expr: syntax error
Can anyone tell me what is wrong in this code?
grep -n "Deep" Formula.xml | cut -d: -f 1
is? In general, it would be better to parse the XML file using an XML parser, such asxmlstarlet
(but I'm a bit confused about what you're wanting XML line numbers for, as the XML format is not line oriented). – Kusalananda Mar 10 '21 at 11:44expr
at the same time would be a problem? What you have is something likeexpr 39806 45608 + 9
. It would be better to tell us what the XML file is and what values needs to be extracted from it to achieve what you want to do. Usinggrep
is not the right approach to reading an XML file. – Kusalananda Mar 10 '21 at 11:48<job>
tag? – Kusalananda Mar 10 '21 at 12:02<job>
and the<Tran>
lines? I don't understand it when you say "or". – Kusalananda Mar 10 '21 at 12:05777
. This is just an example of the 4th line. The file contains other values in the 4th line as well. So i specifically wnt to comment the f4th line after the matching pattern
– DEEP MUKHERJEE Mar 10 '21 at 12:08