问题描述:

I have a text file

Values.txt(contents mentioned below)

IMSI,MSISDN

678,7890

I have an xml with IMSI and MSISDN values specified like this

 <item>

<key>IMSI</key>

<value>404720000000004</value>

</item>

<item>

<key>MSISDN</key>

<value>917329390086</value>

</item>

I have to read the Values.txt and pick the IMSI and MSISDN values and put it into xml in the place of IMSI and MSISDN values.

网友答案:
awk -v FS=, '/[0-9]/{print "<key>IMSI</key>",$1,"<key>MSISDN</key>",$2}' input | \
    sed 's!\([^ ][^ ]*\) \([^ ]*\)!<item>\n\t\1\n\t<value>\2</value>\n</item>\n!g'
相关阅读:
Top