Sed Not Working [Unterminated 'S' Command]

SED not working [unterminated `s' command]

You're missing a separator (which is ~ in your case). It looks like you are trying to put it on the end of $searchString, which is strange. I don't know why you're doing that. The reason it doesn't work is because the variables don't get expanded inside single-quoted strings.

This might work:

sed -i "s~${searchString}\1${replacementString}~g" $file

Really though, it'll be easier to understand like this:

~ $ cat foo
<property name="sourceUrl" value="someurl?param=val"></property>
~ $ searchString='\(<property *name="sourceUrl" *value="\)[^?]*'
~ $ replacementString='file:///tmp/abc-efg'
~ $ sed -e "s~${searchString}~\1${replacementString}~g" foo
<property name="sourceUrl" value="file:///tmp/abc-efg?param=val"></property>

Unterminated `s' command with sed troubleshooting

I can see two things wrong:

  1. There are forward slashes in the string that you're attempting to use in the sed command. These will be interpreted as part of the command, so you should use a different delimiter.
  2. The * is unquoted, so will be glob-expanded by the shell to the names of all the files in the directory.

Reliably using shell variables in string substitutions is non-trivial but can be done using one of the approaches shown in the answers to this question.

In your case, it looks like you can probably get away with using another character as the delimiter, such as @:

sed -i "8s@.*@${psfgen1}@" ./psfgen.inp

Sed unterminated 's command in script

minor1.sed should contain only sed expression, s/8/1/g in your case:

val@chi:~$ cat minor1.sed
s/8/1/g
val@chi:~$ sed -r -f minor1.sed phone.txt
(166) 179-7647
(111) 474-7424
(371) 670-6006
(166) 266-5511
(144) 415-3955
(100) 237-2747

Bash SED Unterminated `s' command

Firstly properly quote bash variable when passing to sed.

Secondly remember that You are passing array into sed.

If that's on purpose You would need to do something like this:

sed -i '1s/.*/'"$(echo ${MODIFIED})"'/' ~/Documents/OSShellScripts/OSScript2.sh

I would also change sed's substitute command s to change line command c, since your variable may contain slashes:

sed -i '1c\'"$(echo ${MODIFIED[@]})"

sed with find return a char 11: unterminated `s' command

One simple solution to try is to place the sed commands in a file and then invoke sed using that file..something like :

find /tmp/ -name myfile -exec sed -r -f sedfile {} \;

Where sedfile contains

N;s/\\([^\\]*\n\s*&& chown -R 82:82)/\1/;P;D

sed unterminated 's' command

Variables get expanded in double quotes, and since $shortName isn't set, it becomes an empty string.

Escape the dollar signs: \$.

Or, if the file you're trying to modify allows exec("date +%Z"); try to switch ' and ". There's no substitution within single quotes.

sed: unterminated `s' command - Can't figure out what needs to be escaped

Both the sed command and the env var contents need escaping.

sed -i "s/{\\\$PROC_MODCONF}/$PROC_MODCONF/g" /etc/procdev/conf.d/modules.cfg.lua

The sed command is in double quotes. That way bash evaluates the env vars in the double quoted string. So the second $PROC_MODCONF will be replaced with its value from the bash environment.

We need to escape the first literal {$PROC_MODCONF} so that bash does not replace it with the value from the environment.

Since the value of $PROC_MODCONF will be placed into the sed command verbatim, that also needs to be escaped.

$ export PROC_MODCONF="Include\\ \"conf.d\/modconf.cfg.lua\""
$ echo $PROC_MODCONF
Include\ "conf.d\/modconf.cfg.lua"


Related Topics



Leave a reply



Submit