我正在尝试在 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.*/" ]
对于您的示例,这有效
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.*/" ]
使用awk和列策略:
$ awk '{$3=$3 "a/sdb[0-9]*$/\042, "; print}' file.txt
filter = [a/sdb[0-9]*$/", "a/sda[0-9]*$/", "r/sd.*/" ]