I have an input xml file like below
INPUT 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 want to comment the tag if i find the pattern "Total Deep" so that the output file looks like below
OUTPUT
<!--<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>
Since i am new to shell scripting, can anyone help me out as to how i can apply this with the help of shell scripting?
awk
. When you detect this tag, collect lines in an array until you reach <entryName>. If it contains Total Deep, write "<!--", then the lines from the array. Write the rest until you hit the closing tag, then write "-->". If it contains something else, do the same but omit the comment strings.