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.
例如我有file.in:
pattern 123 pattern 111
我可以使用 sed 替换此文件中的字符:
sed 's/pattern/replacement/g' file.in > file.out
file.out 将如下所示:
replacement 123 replacement 111
是否可以替换所有不等于模式的字符,如下所示:
pattern replacement pattern replacement
sed '/pattern/!s/.*/replacement/' file.in > file.out
如果模式不匹配,它将替换整行。