awk - Find the value of a variable and replace it with new value in UNIX -


i want access text file , read of contents change them new value.

this find , replace helpful requirement different.

say if these file contents

image.description=template image 08182015 image.version=1.3.111 baseline.name=001_08_18_2015 

i want change them to

image.description=template image 08192015   #19 instead of 18 image.version=1.3.112                       #112 instead of 111 baseline.name=001_08_19_2015                #19 instead of 18 

at point of time not knowing value of each variable know variable name "image version" need script find value of variable image.version , auto increment value next possible integer.

any suggestions/ thoughts?

with gnu awk 3rd arg match():

$ awk 'match($0,/(image\.version.*\.)(.*)/,a){$0=a[1] a[2]+1} 1' file image.description=template image 08182015 image.version=1.3.112 baseline.name=001_08_18_2015 

for others since no arithmetic involved should able use gensub() similarly.

or, maybe kind of thing you're looking for:

$ cat tst.awk begin { fs=ofs="=" } $1=="image.description" { match($2,/.* ../); $2=substr($2,1,rlength) substr($2,1+rlength,2)+1 substr($2,3+rlength) } $1=="image.version"     { match($2,/.*\./);  $2=substr($2,1,rlength) substr($2,1+rlength)+1 } $1=="baseline.name"     { split($2,a,/_/);   $2=a[1]"_"a[2]"_"a[3]+1"_"a[4] } { print }  $ awk -f tst.awk file image.description=template image 08192015 image.version=1.3.112 baseline.name=001_08_19_2015 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -