Unix上用vi和sed进行文本替换:Search/Replace
Unix is a Four Letter Word: Vi —> Search and Replace
VI中: 1,$ s/pattern/newstr/g
用sed更方便: sed -e s/pattern/newstr/g filename > filename.new
谢谢DelphiJ
注意:FreeBSD上是 sed -E
相应的perl脚本: perl -pe ‘~s/pattern/newstr/g’
💬 历史评论
以下 1 条评论从旧版 Movable Type 博客迁移而来。 原始评论时间:2002–2016 年。
Lei · 2004-11-17 14:47
you can try:
perl -pi -e “s/string1/string2/g” filename