how to grep one string occuring multiple times from same file

后端 未结 3 675
北荒
北荒 2021-01-29 14:24

I want to capture a string 1 row affected... But problem is there are no of such string present in the same file.

My concern to capture 1 row affecte

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-29 14:57

    If you have GNU grep, you can make use of its ability to display trailing context of matches:

    cmd... | grep -A 5 "Job completed successfully" | grep "1 row affected"
    

    The first grep will look for the string Job completed successfully, while also providing the five subsequent lines. It is in those lines that the other grep looks for 1 row affected, and prints the match.

提交回复
热议问题