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:
Input file
AAAAAAAAAAAAA
BB 2
CCCCCCCCCCCCC
BB 0.1
Output
AAAAAAAAAAAAA
Now, I want to search for BB and if the second column (2 or 0.1) in that line is bigger than 1, I want to print the previous line.
Can somebody help me with grep and awk? Thanks. Any other suggestions are also welcome. Thanks.
txt awk "BEGIN { R=0; N=0; } /Header pattern/ { N=1; } { R=R+N; N=0; print R; }" ) .
The easiest way to get at the previous line is to make sure that the current line is unfinished (e.g. type \ at the end), accept it (press Enter ), then cancel it (press Ctrl + C ). Then you can recall the whole stored command as a single history line as a single multi-line buffer by pressing Up . Save this answer.
This can be a way:
$ awk '$1=="BB" && $2>1 {print f} {f=$1}' file
AAAAAAAAAAAAA
$1=="BB" && $2>1 {print f}
if the 1st field is exactly BB
and 2nd field is bigger than 1
, then print f
, a stored value.{f=$1}
store the current line in f
, so that it is accessible when reading the next line.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With