-1

When I try following command, I'd like to rewrite sql.

Day='2020/12/1'
Dir=/home/test/data


sql=`cat $Dir"/"$test".sql" | sed -e "s/Day/$Day/g"`

I suffered following errors.

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

Why the s is recognised as option ? why is this command couldnt work well ?

if someone has opinoin, please let me know

Thanks

Heisenberg
  • 4,787
  • 9
  • 47
  • 76

1 Answers1

0

The problem is with slashes: your variable contains them and the final command will be something like sed "s/string/path/to/something/g", containing way too many slashes.

Since sed can take any char as delimiter (without having to declare the new delimiter), you can try using another one that doesn't appear in your replacement string like below:

sql=`cat $Dir"/"$test".sql" | sed -e "s|Day|$Day|g"`

Also, you would need to use sed -i to update the file in-place, since it looks like that is what you're trying to do.