我有这样的行:
storedVars["css_delete_driver"] = "css=.driver:nth-child(2) *[data-method=delete]";
storedVars["css_delete_driver2_mobile"] = "css=a.remove-driver";
我想使用以下方法创建一个文件:
def css_delete_vehicle_everquote
"css=.autos .auto *[data-method=delete]"
end
def css_delete_driver
"css=.driver:nth-child(2) *[data-method=delete]"
end
我怎样才能用 sed 做到这一点?
答案1
以下 sed 将执行此操作:
cat user-extensions.js | sed '
s/storedVars/def /
s/\["//
s/"\]//
s/=/\
/
s/;/ \
end/
'
答案2
适用于s/
每行并且没有内联返回的版本可能是:
cat Variables/user-extensions.js | sed $'
s/storedVars/def /
s/\["//
s/"\]//
s/= /\\\n /
s/;/\\\nend/
'
因为对换行符的$'string'
更改\\\n
详见 https://stackoverflow.com/a/18410122/631619