Re: Search and Replace with Different Text



On Jun 8, 6:08 pm, pk <p...@xxxxxxxxxx> wrote:
On Monday 8 June 2009 15:03, pk wrote:

awk -v len=5 'NR==FNR {repl[FNR]=$0;next}
/<imsi>/{
  $0="<imsi>"sprintf("%0"len"d", repl[++count]) substr($0,12)
}
{print}
' myDataFile CDUSARBFIN2G99277.xml > new.xml

There's an error in that code, sorry.

awk -v len=5 'NR==FNR {repl[FNR]=$0;next}
/<imsi>/{
  sub(/^[[:space:]]*/,"")
  $0="<imsi>"sprintf("%0"len"d", repl[++count]) substr($0,12)
  $0="\t\t\t<imsi>"    # or whatever leading blank you need}

{print}
' myDataFile CDUSARBFIN2G99277.xml > new.xml

This replaces the <imsi>244121000003812</imsi> to just <imsi>.. I want
to replace only the first five digits.. say from
<imsi>244121000003812</imsi> to <imsi>272011000003812</imsi> 27201
being the first or second or any element from the array..
.