Quantcast
Channel: sed: unknown option to `s' - Ask Ubuntu
Viewing all articles
Browse latest Browse all 3

Answer by PerlDuck for sed: unknown option to `s'

$
0
0

The error appears because your variables (at least some of them) contain colons (:) and you use a colon as the delimiter for the s/…/…/ command. Actually for the s:…:…: command in your case.

When you have

var="ex:ample"

and then try to issue

sed -e "s:${var}:sample:g" some_file

then the shell interpolates the variable before handing it over to sed, and sed is called like so:

sed -e "s:ex:ample:sample:g" some_file

and the s:…:…: is now broken. It looks like you are telling sed to replace ex with ample and apply the options s, a, m, p, l, and e.

To avoid this, use a different delimiter which you are sure of it doesn't appear in your text. Popular delimiters are + and # but you can choose any character. The delimiter is in fact the first character after the s, so

sed -e "s#…#…#" some_file
sed -e "s+…+…+" some_file
sed -e "s'…'…'" some_file

will all do.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>