Reputation: 1251
When I run the command
sed -e "s/$1/@root@The-Three-Little-Pigs-Siri-Proxy/" -i gen_certs.sh
I Get the following error. I am trying to replace the text $1 with the other below in the same file, not creating a new one just modifying the current one.
sed: -e expression #1, char 0: no previous regular expression
Any ideas what could be causing the error and how to fix it?
OS: Ubuntu 10.10 32 bit
Upvotes: 3
Views: 1775
Reputation: 161834
$1
will expand to a null-string(''
) if it's in double-qouted string.
You can use single quote to keep the literal value of$1
:
sed -e 's/$1/@root@The-Three-Little-Pigs-Siri-Proxy/' -i gen_certs.sh
Upvotes: 3
Reputation: 32296
You need to escape the pattern: sed -e "s/\$1/@root@The-Three-Little-Pigs-Siri-Proxy/" -i gen_certs.sh
, since $1
denotes a back reference in sed (presuming you want to replace the string $1
in your input, right?)
Upvotes: 1