61

Why this bash script

ssh $SERVER bash <<EOF
sed -i "s/database_name: [^ ]*/database_name: kartable_$ME" $PARAM_FILE
exit
EOF

output ->

sed: -e expression #1, char 53: unterminated `s' command
HalosGhost
  • 4,790
BntMrx
  • 721

3 Answers3

78

The s command in sed, uses a specific syntax:

s/AAAA/BBBB/options

where s is the substitution command, AAAA is the regex you want to replace, BBBB is with what you want it to be replaced with and options is any of the substitution command's options, such as global (g) or ignore case (i).

In your specific case, you were missing the final slash /, if you add it, sed will work just fine:

➜  ~  sed 's/database_name: [^ ]*/database_name: kartable_$ME/'
database_name: something
database_name: kartable_$ME

info sed 'The "s" Command' includes the full description and usage of the s command.

Braiam
  • 35,991
16

Missing / at the end.

sed -i "s/database_name: [^ ]*/database_name: kartable_$ME/" $PARAM_FILE
terdon
  • 242,166
jherran
  • 3,939
  • 1
    it was missing the / not the g, g is for global which may not be desired. –  Nov 19 '14 at 15:29
9

In my case (an unusual issue) I had a \n in my sed command. When I ran it in Jenkins pipeline or copy-paste it, it turned to be a multi-line command and it failed on this error.

The solution was to escape the backslash

OHY
  • 191