sed: -e expression #1, char 15: unterminated `s' command - shell

I have the following shellscript
for i in {1..15..1}
do
sed -i 's/r2.chk/r'$i'.chk' ./ex${i}/r2.gjf
done
which associates to r2.gjf in /ex1, /ex2, etc, it has a line includes r2.chk.
When I run ./sed.sh, I got
sed: -e expression #1, char 15: unterminated `s' command
I found many similar questions on stackoverflow. But, still unsure what's my problem here :(

When I run ./sed.sh, I got sed: -e expression #1, char 15: unterminated `s' command
So terminate the s command - it's missing the /.
sed 's/r2.chk/r'$i'.chk/'
^ - here

Related

sed unix error: unterminated 's' command

Executing this command:
sed -e 's/á/\á/g' ./source_file > ./destiny_file
Shows this error:
sed: -e expression #1, char 14: unterminated `s' command
Sentence is a part of an .sh file.
I had tried on several shells: sh/bash/sch
And the result is the same.
The solution was to codify "á" as "xE1":
sed -e 's/\xE1/\&#225\x3B/g'
This works ok!

bash sed: -e expression #1, char 21: number option to `s' command may not be zero

I want to rewrite a line in a conf file. The text that should be put on line 88 is: auth 0.0.0.0/0 - -
My command is :
sed -i '88s/.*/auth 0.0.0.0/0 - -/' /etc/opt/ss5/ss5.conf
But I'm getting an error
sed: -e expression #1, char 21: number option to `s' command may not be zero
How can I solve this issue ?
It is because the text you try to inject contains / which is used by sed as a separator.
You need either to escape this slash , or to use a different sed separator. Sed can accept any character as separator, i.e #.
sed -i '88s/.*/auth 0.0.0.0\/0 - -/' /etc/opt/ss5/ss5.conf
#OR
sed -i '88s#.*#auth 0.0.0.0/0 - -#' /etc/opt/ss5/ss5.conf

sed: -e expression #1, char 69: unknown command: `0'

I tried using the following sed command to replace a line in the file that I am reading .
sed -i "/$line/c\\${linerep}" "$1"
where $i is the input file where the lines are to be replaced.
I get the following error when I run the script:
sed: -e expression #1, char 65: unknown command: `0'
sed: -e expression #1, char 69: unknown command: `0'
Please tell me what changes should i make in the sed command?
Is there any other way apart from sed to do the same operation?

Error with sed unterminated s command in bash

I'm having a problem with using sed in a bash script.
Here is the line:
sed -i "s/"$name"/"$input"/g" ~/input.script
I'm getting this error:
sed: -e expression #1, char 24: unterminated `s' command
Weirdly enough it was working in an earlier version of my code. I've been trouble shooting but I cannot find a solution.
You don't need nested quotes. Also, try changing the delimeter:
sed -i "s#$name#$input#g" ~/input.script

using sed with local variables that have /

I'm trying to make the sed command replace these:
CURRENT_TOMCAT=/opt/tomcat/lib
NEW_TOMCAT=/usr/tomcat/lib
sed -i "s/$CURRENT_TOMCAT/$NEW_TOMCAT/" tomcat.env
I've tried a bunch of combinations with no success, sometimes getting the unknown option to `s' error, sometimes getting no errors, but no changes are made
The line I that needs to be change looks like this:
TOMCAT_LIB=/opt/tomcat/lib; export TOMCAT_LIB
Try changing the delimiter to another one not contained in your strings. For example, #:
CURRENT_TOMCAT=/opt/tomcat/lib
NEW_TOMCAT=/usr/tomcat/lib
sed -i "s#$CURRENT_TOMCAT#$NEW_TOMCAT#" tomcat.env
^ ^ ^
Test
$ cat a
hello/how are you?
$ old="hello/how"
$ new="bye/how"
$ sed "s/$old/$new/" a
sed: -e expression #1, char 13: unknown option to `s' <---- meeec
$ sed "s#$old#$new#" a
bye/how are you? <---- successful!

Resources