Print previous line if condition is met

后端 未结 4 1067

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 11:15

    Combining sed & awk you get this: sed 'N;s/\n/ /' < file |awk '$3>1{print $1}'

    sed 'N;s/\n/ / : Combine 1st and 2nd line and replace next line char with space

    awk '$3>1{print $1}': print $1(1st column) if $3(3rd column's value is > 1)

提交回复
热议问题