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:
- 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.
- 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
containsN;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
Stop Being Root in the Middle of a Script That Was Run with Sudo
Replace Bash Variables in Template File
Usb Modem Is Echoing Back Wrong Characters
Multiple -A with Greater Than/Less Than Break Bash Script
Overhead of Supporting Floating Point Arithmetic Inside the Linux Kernel
How to Make a Bash String of Command with Redirect and Pipe
How to Scale Ejabberd Server MAChine on Centos to Handle 200 K Connections
Error Cl_Device_Not_Available When Calling Clcreatecontext (Intel Core2Duo, Intel Ocl Sdk 3.0 Beta)
Why Can't Cuda's Examples Makefile Find the Cuda Libraries
How to Solve "Bash: Ls: Command Not Found"
"Echo" Output Different Answer by Sh and Bash
Hash ("#") Symbol in /Etc/Environment Causes String to Be Split
Can Someone Explain the Shell Shock Bash Code
Unix How to Block Unix/Linux 'Wall' Messaging
Pthread Condition Variables on Linux, Odd Behaviour
Significance of Address 0X8048080
Re-Encoding Only Images of a PDF? (Or, Ghostscript Fails on 8-Bit Rgb While Optimizing)