I have an “example_file” like below,
a2022.1 a2022.1 80
a2022.1 a2022.2 90
a2022.1 a2023.1 80
a2022.2 a2022.2 90
a2022.2 a2023.1 40
a2022.3 a2022.1 50
b20225.1 a2022.1 80
and I would like to select lines which has the third column > 80 and also has the 1st column (before the dot) different from the 2nd column (before the dot).
So the desired result would be
a2022.1 a2023.1 80
b20225.1 a2022.1 80
So I already managed to exclude the lines with 3rd column <80 and with the same 1st and 2nd column by using the line below
awk '($3 > 80 && $1!=$2)' example_file
and I tried awk '($3 > 80 && $1!~$2)' example_file
, but it does not exclude the line
a2022.1 a2022.2 90
I thought it could be easy, but I can’t figure it out. Could somebody help? Thanks!
You may use this
awk
:Here
-F '[.[:blank:]]'
sets input field separator to a dot or whitespace character. This allows us to use parts of first column as$1
and$2
and second column as$3
and$4
.Alternatively using
gnu-awk
: