how to use grep to match with either whitespace or newline

前端 未结 3 627
孤街浪徒
孤街浪徒 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:38

    Use "AAA\b" if it's acceptable to also match AAA followed by any other non-alphanumeric character. According to the grep man pages, \b matches the empty string at the edge of a word.

    $ echo -e "AAA VVV \nVVV AAA\nBBB" | grep "AAA\b"
    AAA VVV
    VVV AAA
    

提交回复
热议问题