Input file contains:
[abc]
para1=123
para2=456
para3=111
[pqr]
para1=333
para2=765
para3=1345
[xyz]
para1=888
para2=236
para3=964
Requirement of shell script is to replace the one parameter of particular block
Ex: Replace para2=765
with para2=999
of block [pqr]
Please help me how can I achieve this with sed
or awk
command.
This might work for you (GNU sed):
Substitute the number following
para2=
within the block starting[pqr]
to an empty line.THE idiomatic awk solution is:
Through sed another way,
Here is how I would do it:
By setting
RS
to nothing, you makeawk
work in block mode separated by blank lines.Then make sure we are in correct block by search for block starting with
[pqr]
In this block, change the data from
para2=765
topara2=999
, then print it.Another way to do it:
Set a flag if
pqr
is found, change the data if flag is true, reset the flag.