xen*_*ide 10 command-line shell grep text-processing
我有一长串域名需要从 /etc/remotedomains 中删除。它们在文件中可能没有任何特定的顺序。每个域在一行上。
我如何遍历列表并在远程域中找到该行并将其删除。
sep*_*p2k 11
grep -Fxf list -v /etc/remotedomains > remotedomains.new
mv remotedomains.new /etc/remotedomains
Run Code Online (Sandbox Code Playgroud)
该-v
告诉grep来不匹配的模式只输出线。
该-f list
告诉grep来从文件中读取模式list
。
该-F
告诉grep来解释模式为纯字符串,而不是正则表达式(这样你就不会遇到与正则表达式元字符的麻烦)。
该-x
告诉grep来整条生产线相匹配,例如,如果有一个模式foo
只应删除行foo
,也不行foobar
或barfoo
。