sed find replace regex用mixin重新绘制CSS转换
我有12k行SCSS代码,我需要像这样替换所有CSS转换:sed find replace regex用mixin重新绘制CSS转换,regex,bash,sed,Regex,Bash,Sed,我有12k行SCSS代码,我需要像这样替换所有CSS转换: transition: background .3s ease; 或 带着一种粗鲁的态度 @include _transition(background .3s ease); 经过大量研究,我最终得到了这样一个sed命令 sed -i '' 's/transition: ([a-zA-Z0-9.]*);/@include _transition\((\1)\);/' * 但这当然行不通。我正在使用Mac电脑,我得到的错误是: se
transition: background .3s ease;
或
带着一种粗鲁的态度
@include _transition(background .3s ease);
经过大量研究,我最终得到了这样一个sed命令
sed -i '' 's/transition: ([a-zA-Z0-9.]*);/@include _transition\((\1)\);/' *
但这当然行不通。我正在使用Mac电脑,我得到的错误是:
sed: 1: "s/transition: ([a-zA-Z0 ...": \1 not defined in the RE
请帮忙 您需要在字符类中添加
空格
,而不需要在替换部件中转义(
,)
。正常sed使用BRE(基本正则表达式),因此捕获组必须类似于\(blah blah\)
而不是(blahblah)
示例:
$ cat file
transition: background .3s ease;
foo
$ sed 's/transition: \([a-zA-Z 0-9.]*\);/@include _transition(\1);/g' file
@include _transition(background .3s ease);
foo
我不认为它适用于第二个例子。我明白了:
-webkit-@include\u转换(background.3s ease)代码>@AvinashRaj你太棒了,你的答案也太棒了。这很有效。@David你说得对。我这样做是因为首先我运行了sed,它替换了所有带前缀的webkit转换,然后第二个替换了不带前缀的转换。
sed 's/transition: \([a-zA-Z 0-9.]*\);/@include _transition(\1);/g' file
$ cat file
transition: background .3s ease;
foo
$ sed 's/transition: \([a-zA-Z 0-9.]*\);/@include _transition(\1);/g' file
@include _transition(background .3s ease);
foo