3

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
sourav c.
  • 44,715
Don
  • 293

1 Answers1

3

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'
FOOBAR

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
    
heemayl
  • 91,753