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
Related
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/\á\x3B/g'
This works ok!
I keep getting the following error:
sed: -e expression #1, char 29: invalid reference \1 on `s' command's RHS
grep -l 'someFiles' | xargs sed -r 's/<add fileName="\(.+?\)"/\1/g'
I am escaping the () as I have read to do in other files, I have also tried to work through it elsewhere:
https://regex101.com/r/tU9qV4/2
so I know my regex is working, I have also tested my grep, I am actually using a few exclusions and things in the statement, but it's outputting exactly what I need. Why am I still not able to use the \1?
I am using shell script. My requirement is to find and replace the string. The string contains "/" char as well. I am getting error sed: -e expression #1, char 18: unterminated `s' command. Can someone tell how should i replace the string which has "/"?
#!/bin/bash
...
search_string="../conf/TestSystem/Inst1.xml"
rep="Inst1/Instrument.xml"
sed -i 's|${line}|${rep}/g' MasterConfiguration.xml
I tried using another sed command but that one also gave error sed: -e expression #1, char 13: unknown option to `s'
sed -e "s/${line}/${rep}/g" MasterConfiguration.xml > tempfile
Whenever you deal with shell-variables you have to get them out of the "sed-string":
For example:
sed -e "s/"${line}"/"${rep}"/g" MasterConfiguration.xml > tempfile
Otherwise sed will treat the chars as-is and search for ${line} literally:
As you see, nothing happens here.
Furthermore, if your variables contain / you need to use another delimiter for sed. I tend to use ~ in such a case, but you're free to use other chars - just be consequent and don't mix them like in your first example-sed-command:
sed 's~'${line}'~'${rep}'/g' //WRONG
sed 's~'${line}'~'${rep}'~g' //RIGHT
Combine both and it will work:
You can try this sed,
sed -i "s#${line}#${rep}#g" MasterConfiguration.xml
Problem:
Instead you have,
sed -i "s|${line}|${rep}/g" MasterConfiguration.xml
It should be,
sed -i "s|${line}|${rep}|g" MasterConfiguration.xml
Syntax:
sed "s|pattern|replacement|g"
Right, so in a Bash script I have the following line:
sed -i 's/$/,"123456","789101112","0001",'"$THEDATE"',"DDX"/' /tmp/tmp02.csv
However, whenever I run it I always get the error
sed: -e expression #1, char 42: unknown option to `s'
I think it's the variable bit, but however I do it it won't seem to escape the double quotes.. Any help greatly appreciated!
I think you have slashes in THEDATE, which are being confused as regex delimiters by sed. Try changing the substitution delimiter, for example with !:
sed -i 's!$!,"123456","789101112","0001",'"$THEDATE"',"DDX"!' /tmp/tmp02.csv
I am calling sed from my Makefile, and this line doesn't work:
sed -i -r 's|^(3)$|5|' file;
It's perfectly fine if I call from the terminal, but GNU make reports the following error:
sed: -e expression #1, char 8:
unterminated `s' command
Any ideas how I can fix this, and could you provide any manual on how Makefile deals with strings? Thanks.
$ has a special meaning in makefiles. Use $$ cancel it:
sed -i -r 's|^(3)$$|5|' file;