Print previous line if condition is met

后端 未结 4 1066

I would like to grep a word and then find the second column in the line and check if it is bigger than a value. Is yes, I want to print the previous line.

Ex:

In

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-08 10:52

    Another option: reverse the file and print the next line if the condition matches:

    tac file | awk '$1 == "BB" && $2 > 1 {getline; print}' | tac
    

提交回复
热议问题