regex - how to do recursive replacement with incremented alphanumeric value in a file using sed/awk/perl -


how can make shell script using sed or awk recursive replacement of same value incremented alphanumeric values , inside again recursive incremented alphanumeric values. should happen till nth value end of file

---input file follow----

<first line has same value testname="tran cont" enabled="true">     <inner first line has url testname="/" enabled="true">     <inner second line has url testname="/test/dui/views?" enabled="true"> <first line has same value testname="tran cont" enabled="true">     <inner first line has url testname="/test/tedi/perf" enabled="true">     <inner second line has url testname="/dest/content/surf" enabled="true">     <inner third line has url testname="/cest/dui/duff" enabled="true"> <first line has same value testname="tran cont" enabled="true">      <inner first line has url testname="/test/dui/complete" enabled="true">      <inner second line has url testname="/test/dui/one" enabled="true">      <inner third line has url testname="/test/dui/two" enabled="true"> 

---output required follow----

<first line has same value testname="a01" enabled="true">     <inner first line has url testname="a01_01" enabled="true">     <inner second line has url testname="a01_02_views?" enabled="true"> <first line has same value testname="a02" enabled="true">     <inner first line has url testname="a02_01_perf" enabled="true">     <inner second line has url testname="a02_02_surf" enabled="true">     <inner third line has url testname="a02_03_duff" enabled="true"> <first line has same value testname="a03" enabled="true">     <inner first line has url testname="a03_01_complete" enabled="true">     <inner second line has url testname="a03_02_one" enabled="true">     <inner third line has url testname="a03_03_two" enabled="true"> 

here going:

awk  -f\" '/^<first/ {a++;b=0} {n=split($2,s,"/");q=s[n];$2="a0"a ($0~/<inner/?"_0"++b"_"q:"")}1' ofs=\" file <first line has same value testname="a01" enabled="true">     <inner first line has url testname="a01_01_" enabled="true">     <inner second line has url testname="a01_02_views?" enabled="true"> <first line has same value testname="a02" enabled="true">     <inner first line has url testname="a02_01_perf" enabled="true">     <inner second line has url testname="a02_02_surf" enabled="true">     <inner third line has url testname="a02_03_duff" enabled="true"> <first line has same value testname="a03" enabled="true">      <inner first line has url testname="a03_01_complete" enabled="true">      <inner second line has url testname="a03_02_one" enabled="true">      <inner third line has url testname="a03_03_two" enabled="true"> 

how works:

awk  -f\" '                                 # set field separator " /^<first/ {                                 # if record starts <first do:     a++                                     # increment variable     b=0}                                    # set b 0     {                                       # run do:     n=split($2,s,"/")                       # split data in field 2, array s slitted /. sen variable n number of data in array s     q=s[n]                                  # set variable q last element in array s     $2="a0"a ($0~/<inner/?"_0"++b"_"q:"")   # set field 2 to: "a0" + value of + ( if $0 equal "inner" "_0" b (auto increment) "_" q, else "")      } 1                                           # print line ' ofs=\" file                               # set output field separator " , read file 

Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

how to receive file in java(servlet/jsp) -