How to give a pattern for new line in grep?

前端 未结 6 595
予麋鹿
予麋鹿 2020-12-02 06:19

How to give a pattern for new line in grep? New line at beginning, new line at end. Not the regular expression way. Something like \\n.

6条回答
  •  抹茶落季
    2020-12-02 06:27

    try pcregrep instead of regular grep:

    pcregrep -M "pattern1.*\n.*pattern2" filename
    

    the -M option allows it to match across multiple lines, so you can search for newlines as \n.

提交回复
热议问题