我需要在lvm.conf
文件中找到以 string 开头的行,global_filter
并删除方括号之间的所有内容(除了"r/.*/"
.
只有 1 行以 global_filter 开头。
拆除前:
global_filter = [ "a|^/dev/sda.*$|", "a|^/dev/sdb.*$|", "r/.*/"]
删除后,应该是 -
global_filter = [, "r/.*/"]
答案1
sed -i -e '/^global_filter/{\|"r/\.\*/"|s|.*|global_filter = [, "r/.*/"]|;}' data
解释
sed -i -e '
# look at only lines that begin with global_filter
/^global_filter/{
# and also they should contain the string "r/.*/"
# change everything to the following expression
\|"r/\.\*/"| s|.*|global_filter = [, "r/.*/"]|
## alternatively could be written:
#\|"r/\.\*/"|c\
#global_filter = [, "r/.*/"]
}
' data
答案2
尝试这个:
$ echo 'global_filter = [ "a|^/dev/sda.$|", "a|^/dev/sdb.$|", "r/.*/"]'|\
sed -E 's/(^global_filter = \[)(.*)(, "r.*$)/\1\3/'
输出:
global_filter = [, "r/.*/"]