how to use grep to match with either whitespace or newline

前端 未结 3 566
孤街浪徒
孤街浪徒 2021-01-07 20:18

I want to grep a file with a word, say \"AAA\", and it ends with whitespace or newlines. I know how to write this seperately, as follows, but having problems in combining th

3条回答
  •  有刺的猬
    2021-01-07 20:31

    You can use the -e option of grep to select many patterns:

    grep -e "AAA$" -e "AAA[[:space:]]"
    

    From the grep man:

    -e PATTERN, --regexp=PATTERN
          Use  PATTERN  as  the  pattern.   This  can  be  used to specify
          multiple search patterns, or to protect a pattern beginning with
          a hyphen (-).  (-e is specified by POSIX.)
    

提交回复
热议问题