我正在尝试用linux中的文件中的特殊字符替换下面指示的字符串。我尝试在每个特殊字符前面使用反斜杠,但是会出错。必须遗漏一些东西。我如何实现以下目标。提前致谢:
filter = [ "a/sda[0-9]*$/", "r/sd.*/" ] ---> Replace this line with below line
filter = [ "a/sda[0-9]*$/", "a/sdb[0-9]*$/", "r/sd.*/" ]
答案 0 :(得分:1)
对于你的例子,这工作
sed 's@",@", "a/sdb[0-9]*$/",@'
输出:
kent$ echo 'filter = [ "a/sda[0-9]*$/", "r/sd.*/" ]'|sed 's@",@", "a/sdb[0-9]*$/",@'
filter = [ "a/sda[0-9]*$/", "a/sdb[0-9]*$/", "r/sd.*/" ]
答案 1 :(得分:0)
使用awk和列策略:
$ awk '{$3=$3 "a/sdb[0-9]*$/\042, "; print}' file.txt
filter = [a/sdb[0-9]*$/", "a/sda[0-9]*$/", "r/sd.*/" ]