sed throws'bad flag in substitute command' [英] sed throws 'bad flag in substitute command'
问题描述
我想在一个CSS文件中运行一个简单的命令,将绝对路径替换为相对路径,如下所示:
sed - i'/ \ / fonts /../ fonts /'/Users/sergeybasharov/WebstormProjects/snap/compiled/Content/stylesheets/style.css
它抛出此
sed:1:/ Users / sergeybasharov / W ...:替换命令中的错误标志:'b'
$ <$ p
-i
选项(用于备份文件的后缀)的参数,并且filename参数被视为编辑命令。 您需要指定禁用备份文件创建:
sed -i''...
在您的示例中:
sed -i'''/ \ / fonts /../ fonts /'/ Users / sergeybasharov / WebstormProjects / snap / compiled / Content / stylesheets /style.css
计算机是愚蠢的,他们不会根据上下文来计算事物,所以他们可以'显然是一个编辑命令,而不是一个后缀。
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/sergeybasharov/WebstormProjects/snap/compiled/Content/stylesheets/style.css
It throws this
sed: 1: "/Users/sergeybasharov/W ...": bad flag in substitute command: 'b'
What can be wrong in this simple script?
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.
这篇关于sed throws'bad flag in substitute command'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!