0

I have an XML file which contains below

<SummaryRecordMapping>
<eName>Licensed Original MC TPE EXCESSIVE AUTH</eName>
<jobs>
<job>

<SummaryRecordMapping>
<eName>Licensed Reversal MC TPE EXCESSIVE AUTH</eName>
<jobs>
<job>

where, <eName>Licensed Original, </eName> , <eName>Licensed Reversal are static.

I want output like below

<SummaryRecordMapping>
<eName>Licensed Original MC This is New Deep</eName>
<jobs>
<job>

<SummaryRecordMapping>
<eName>Licensed Reversal MC This is New Deep</eName>
<jobs>
<job>

<SummaryRecordMapping>
<eName>Licensed Original MC This is Mayurika</eName>
<jobs>
<job>

<SummaryRecordMapping>
<eName>Licensed Reversal MC This is Mayurika</eName>
<jobs>
<job>

Below is my code

#!/bin/bash
while read whole_line ;
do
name=`echo "$whole_line" | awk '{$1=""; print}'`
LO="<eName>Licensed Original MC ${name}</eName>"
awk -v diff="$LO" '{ if(NR==2) { print diff}
                              else {print $0} } ' southBalanceRecon.xml >>LO.xml

LR="<eName>Licensed Reversal MC ${name}</eName>"
awk -v diff="$LR" '{ if(NR==14) { print diff}
                              else {print $0} } ' LO.xml >> LR.xml
done < file.txt

My file.txt contains below

C71 This is New Deep
C72 This is Mayurika

When I am trying to run my code I am not getting the probable output which I mentioned above. Can anyone tell me what is wrong with my code?

0

Try this,

while IFS= read -r line; do
    NAME="`echo "$line" | awk '{$1=""; print}'`"
    sed "s#^<eName>Licensed Original.*</eName>#<eName>Licensed Original$NAME</eName>#;s#^<eName>Licensed Reversal.*</eName>#<eName>Licensed Reversal$NAME</eName>#" LO.xml >> LR.xml
done < input.txt
  • 1
    Wow Great. Thanks a lot. It worked – Riju Mukherjee Aug 23 at 11:31
0

How do you feel with this solution:

sed -i -E -e "s/(Original|Reversal) .*</\1$(sed '1q;d' file.txt)</" -e 's/C[0-9]*//' file.xml

text="$(cat foo)" && echo "$text" \
| sed -E -e "s/(Original|Reversal) .*</\1$(sed '2q;d' file.txt)</" -e 's/C[0-9]*//' >> file.xml

Find the pattern Origina|Reversal until the <

sed -i -E -e "s/(Original|Reversal) .*</

Replace with the first line of file.txt

    /\1$(sed '1q;d' file.txt)</" -e 's/C[0-9]*//' file.xml

Copy the content of the xml file and repeat the operation, this time with the second line of file.txt and append the output to the xml file

text="$(cat foo)" && echo "$text" \
| sed -E -e "s/(Original|Reversal) .*</\1$(sed '2q;d' file.txt)</" -e 's/C[0-9]*//' >> file.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.