sed throws 'bad flag in substitute command'

后端 未结 3 919
闹比i
闹比i 2020-12-14 05:34

I want to run a simple command of replacing absolute paths to relative ones inside a CSS file like this:

sed -i \'s/\\/fonts/../fonts/\' /Users/sergeybasharo         


        
相关标签:
3条回答
  • 2020-12-14 06:10

    sed -i 's/\/fonts/../fonts/' is not a valid sed command, try sed -i 's#/fonts#../fonts#'

    0 讨论(0)
  • 2020-12-14 06:17

    I was having a similar issue. You can install the GNU version of sed in your Mac, called gsed, and use it using the standard Linux syntax.

    For that, install gsed using ports (if you don't have it, get it at http://www.macports.org/) by running sudo port install gsed. Then, you can run gsed -i 's/old_pattern/new_pattern/g' *

    0 讨论(0)
  • 2020-12-14 06:37

    In your command s/\/fonts/../fonts/ is being taken as the parameter to the -i option (the suffix to use for the backup file), and the filename argument is being treated as the editing commands.

    You need to specify to disable the backup file creation:

    sed -i '' ...
    

    In your example:

    sed -i '' 's/\/fonts/../fonts/' /Users/sergeybasharov/WebstormProjects/snap/compiled/Content/stylesheets/style.css
    

    Computers are dumb, they don't figure things out by context, so they can't tell that something beginning with s/ is obviously an editing command, not a suffix.

    0 讨论(0)
提交回复
热议问题