sivakumar V
sivakumar V

Reputation: 135

How to pass the path name to sed

I tried to pass the search pattern as path to sed, but it is not taking the path name. It is showing the error as "sed: command garbled". Here is the used code,

sed -e "/$node/s/^/#/" /etc/inittab > /etc/inittab.new && sudo mv /etc/inittab.new /etc/inittab

Here i am passing the search pattern as "opt/product/BETA/scp_install/bin/startBETAscp", and i am getting the error as "sed: command garbled: /(opt/product/BETA/scp_install/bin/startBETAscp)/s/^/#/"

Please suggest me, how to use the content of the variable into the search.

Upvotes: 0

Views: 188

Answers (1)

Kent
Kent

Reputation: 195219

with sed you can check the regex match by /pattern/, the / could be char other than / (slash). the format is \@pattern@ (here @ is the example). So your line would be:

sed "\@$node@s/^/#/" ....

add how it worked:

kent$ (master|✔) v="a/b/c"

kent$ (master|✔) sed "\@$v@s/^/#/" <<< "foo  
dquote> a/b/c"
foo
#a/b/c

Upvotes: 3

Related Questions