I have a xml input file which contains below
INPUT FILE
<Formula>
<name>Total Invoices Released</name>
<comment></comment>
<sumType>Suspense</sumType>
<operands>
<operand>Total Hui Invoice Released</operand>
<operand>Total hdrt Invoices Released</operand>
<operand>Total hgfyu Invoices Released</operand>
<name>Total Deep Invoice Released</name>
<comment></comment>
<sumType>Suspense</sumType>
<operands>
<operand>-Total Deep Licensed Original </operand>
<operand>-Total Deep Licensed Original </operand>
<operand>-Total Deep Licensed Original </operand>
I want to search with "Total Invoices Released" and add some text after 4 lines of the matching pattern from file.txt. Similiarly i want to search "Total Deep Invoice Released" and add some text after 4 lines of the matching pattern from file.txt. Th eoutput will be like below
I want an Output file like below
OUTPUT FILE
<Formula>
<name>Total Invoices Released</name>
<comment></comment>
<sumType>Suspense</sumType>
<operands>
<operand>-Total Licensed Original This is he</operand>
<operand>-Total Licensed Reversal This is he</operand>
<operand>-Total Licensed Original This is she</operand>
<operand>-Total Licensed Reversal This is she</operand>
<operand>Total Hui Invoice Released</operand>
<operand>Total hdrt Invoices Released</operand>
<operand>Total hgfyu Invoices Released</operand>
<name>Total Deep Invoice Released</name>
<comment></comment>
<sumType>Suspense</sumType>
<operands>
<operand>-Total Deep Licensed Original This is he</operand>
<operand>-Total Deep Licensed Reversal This is he</operand>
<operand>-Total Deep Licensed Original This is she</operand>
<operand>-Total Deep Licensed Reversal This is she</operand>
<operand>-Total Deep Licensed Original </operand>
<operand>-Total Deep Licensed Original </operand>
<operand>-Total Deep Licensed Original </operand>
I have coded but it is not giving me the expected output.
CODE
#!/bin/bash
IR=`grep -n "<name>Total Invoices Released</name>" BalanceForm.xml | cut -d: -f 1`
VIR=`grep -n "<name>Total Deep Invoice Released</name>" BalanceForm.xml | cut -d: -f 1`
TOTAL=`expr $IR + 4`
TOT=`expr $VIR + 4`
while IFS= read -r line; do
NAME="`echo "$line" | awk '{$1=""; print}'`"
sed -i "{
${TOTAL}i\<operand>-Total Licensed Original $NAME</operand>
${TOTAL}i\<operand>-Total Licensed Reversal $NAME</operand>
${TOT}i\<operand>-Total Deep Licensed Original $NAME</operand>
${TOT}i\<operand>-Total Deep Licensed Reversal $NAME</operand>
}" BalanceForm.xml
done < file.txt
The input file is like below
INPUT FILE
C71 This is He
C72 This is She
Can someone tell me whats wrong with the code