使用 sed 解释为固定字符串/文字而不是正则表达式 [英] Interpret as fixed string/literal and not regex using sed

查看:51
本文介绍了使用 sed 解释为固定字符串/文字而不是正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于grep,有一个固定的字符串选项,-F (fgrep) 来关闭搜索字符串的正则表达式解释.sed 是否有类似的功能?我在男人身上找不到任何东西.推荐另一个 gnu/linux 工具也可以.

For grep there's a fixed string option, -F (fgrep) to turn off regex interpretation of the search string. Is there a similar facility for sed? I couldn't find anything in the man. A recommendation of another gnu/linux tool would also be fine.

我使用 sed 来实现查找和替换功能:sed -i "s/abc/def/g"

I'm using sed for the find and replace functionality: sed -i "s/abc/def/g"

推荐答案

您应该使用 replace 而不是 sed.

You should be using replace instead of sed.

来自手册页:

   The replace utility program changes strings in place in files or on the
   standard input.

   Invoke replace in one of the following ways:

       shell> replace from to [from to] ... -- file_name [file_name] ...
       shell> replace from to [from to] ... < file_name

   from represents a string to look for and to represents its replacement.
   There can be one or more pairs of strings.

这篇关于使用 sed 解释为固定字符串/文字而不是正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆