My sed command works fine on the command line but when I put it in a bash script and call it with

sed -e sedscript.sh

I get

$ sed -e sedscript.sh
sed: -e expression #1, char 12: unterminated `s' command

This is the sedscript.sh:

$cat sedscript.sh
sed 's/^ *[0-9]\+.//g' tictactoeold.py>tictactoenew.py
  • 1
    I believe the -e option is to add a sed script, not a shell script. – Byte Commander Sep 27 '16 at 11:40

The -e option of sed is to input a valid sed expression, not a file name containing sed commands, the -f option is for filename containing valid sed expressions.

In your case:

sed -e sedscript.sh

is being treaded as a substitution (s) operation of sed as the expression starts with s, with e as the delimiter for s (substitution), and sed is rightly complaining about the unterminated s (substitution) command.

Have fun:

% sed -e sedscript.sheFOOe <<<'dscript.shBAR'

What you can do:

  • Your file is necessarily a shell script, you can simple execute that as so

  • Use -e to put the expession on the command line directly, -e is not strictly needed though:

     sed 's/^ *[0-9]\+.//g' tictactoeold.py >tictactoenew.py 
     sed -e 's/^ *[0-9]\+.//g' tictactoeold.py >tictactoenew.py 
  • Use the -f option, and just keep the sed expressions in the file only i.e. make the file sedscript as:

    s/^ *[0-9]\+.//g

    and then use the sed command as:

    sed -f sedscript tictactoeold.py >tictactoenew.py

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.