How to grep asterisk without escaping?

后端 未结 2 1193
旧时难觅i
旧时难觅i 2021-01-02 18:42

Suppose I have a file abc.txt which contains line ab*cd. When I grep that pattern ab*cd with quotes but without escaping

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 19:04

    Use the flag -F to search for fixed strings -- instead of regular expressions. From man grep:

       -F, --fixed-strings
              Interpret  PATTERN  as  a  list  of  fixed strings, separated by
              newlines, any of which is to be matched.  (-F  is  specified  by
              POSIX.)
    

    For example:

    $ grep -F "ab*c" <<< "ab*c"
    ab*c
    

提交回复
热议问题