Using -e option with sed to run sed from a script fails

Don

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
heemayl

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
    

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

sed: -e expression #1, char 23: unknown option to `s'

From Dev

sed unknown option to `s' in bash script

From Dev

SED command not being run from bash script

From Dev

How to run sed command from java code

From Dev

sed not working from within bash script

From Dev

sed: Using a variable in sed

From Dev

Sed - unknown option to `s'

From Dev

Using sed output in another script or command

From Dev

Editing a script using grep and sed

From Dev

Using sed to remove string from list of files fails

From Dev

Remove line from file in bash script using sed command

From Dev

How to run sed command from java code

From Dev

Removing "<<" and ">>" from a file using a sed script

From Dev

sed command with option -n and '$='

From Dev

What does `-e` option in sed do?

From Dev

Sed : unknown option to `s'

From Dev

bash/sed script to get output from a file using a regex

From Dev

Run sed command in perl script

From Dev

Using output of diff -e with sed

From Dev

Using cut and sed command at the same time in a script

From Dev

How can I avoid creation of the extra file with `-e` while using the sed tool in a shell script?

From Dev

use sed to execute a shell script if search fails

From Dev

How to combine several option in sed -e command?

From Dev

sed :unknown option to `s' in my sed script

From Dev

Using sed on OSX bash script

From Dev

Using sed to update crontab job minutes and hour from script

From Dev

Can't run sed command on Bash script

From Dev

using sed from a seperate file

From Dev

Command pipeline run out of Perl fails at sed prepending a path