sed replacement error

Hi

,"environment":"accent-release","build":"ac-1112_c_Alph_Nop-release_rele-1112_c_Alph_Nop-release_rele","tags":""

above is the config file, where in i want to replace value after build inside the double quotes... that value i'll be passing as parameter

for example if m passing

./a.sh abcd release, the o/p shul be

,"environment":"accent-release","build":"abcd release","tags":""

i tried below sed command, but to no avail

sed -e 's/"build":[[:alnum:]\{1,\}/"build":${parm}/g'

Try this awk solution:

awk -F, '{for (i=1; i<=NF; i++) if ($i~/^"build":/) $i="\"build\":\"" PARM "\""}1' PARM="abcd release" OFS="," file
,"environment":"accent-release","build":"abcd release","tags":""

---------- Post updated at 16:35 ---------- Previous update was at 16:30 ----------

or a sed version (single quotes stop the shell from expanding variables):

sed -Ee "s/(\"build\":)[^,]*/\1${parm}/" file
1 Like