Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我目前有这个sed命令替换foo.us.param=value为foo.param=value:
sed
foo.us.param=value
foo.param=value
sed -i -e 's/\.us\./\./p' file.txt
问题是它创建了它匹配的每一行的副本。如果我添加 a-n它会删除所有与正则表达式不匹配的行。
-n
如何修复它以保留不匹配的行并且只输出它编辑一次的行?
只需删除成功替换后再次打印该行的p标志:sed
p
sed -i 's/\.us\./\./' file.txt