Goku
Goku

Reputation: 534

grep and replace multi line values in bash

How to uncomment the below lines efficiently from my config file.

#PPD=/home/mine/ppd (Line no. 100)
#_dco_ppd.c \
#       -DUSE_LIC -I$(LIC)/include -I$(LIC)/include/grok.c \
#       -L$(LIC)/lib -llic -lokta

I tried below options none worked

grep -A 4 "PPD=/home/mine/ppd" config | xargs 0 sed -i 's/^#//g' [threw below error]

sed: invalid option -- 'D' Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...

Other tries

sed -i 's|#PPD=/home/mine/ppd|PPD=/home/mine/ppd|' config (worked)
sed -i 's|#_dco_ppd.c|_dco_ppd.c|' config (worked)
sed -i 's|#       -DUSE_LIC|       -DUSE_LIC|' config (didnt work)
sed -i 's|#-DUSE_LIC|-DUSE_LIC|' config (didnt work as well)

Where am I going wrong ?

I'm on 14.04.1-Ubuntu Docker container

GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu)

Upvotes: 0

Views: 93

Answers (1)

Raman Sailopal
Raman Sailopal

Reputation: 12927

sed -Ei '/^#PPD/,/^#.*-lokta$/{s/#//}' configfile

Look for the text required in your sed statement

/^#PPD/ - line beginning with (^) #PPD to (signified by ,) ...

/^#.*-lokta$/ - line beginning with (^) #, then anything, then -lokta, end of line ($)

Then execute the substitution enclosed within {}

Upvotes: 3

Related Questions