How to grep rows that have certain value in a specific column?
You don't use grep. Use awk
.
"your data" | awk '$1 ~ /\.[05]00/'
awk '$1 ~ /\.[50]00/ { print $0 }' myFile.txt
The first column $1
will be matched against /\.500|\.000/
the dots are escaped to be literal dots not regex any character the ~
is partial match, and print the whole line $0
I would like to grep only the rows that have in the first column the decimal .000 and .500
My first thought
grep '^ *[0-9][0-9][0-9]\.[50]00' filename
Quick test using WSL
$ head testdata
200.000 1.353 0.086
200.250 1.417 0.000
200.500 1.359 0.091
200.750 1.423 0.000
201.000 1.365 0.093
201.250 1.427 0.000
201.500 1.373 0.093
201.750 1.432 0.000
202.000 1.383 0.091
202.250 1.435 0.000
$ grep '^ *[0-9][0-9][0-9]\.[50]00' testdata
200.000 1.353 0.086
200.500 1.359 0.091
201.000 1.365 0.093
201.500 1.373 0.093
202.000 1.383 0.091
202.500 1.392 0.087
203.000 1.402 0.081
203.500 1.412 0.073
204.000 1.423 0.065
204.500 1.432 0.055
205.000 1.441 0.045
There are more concise ways to express this.
$ grep -E '^ *[0-9]{3}\.[50]00' testdata
200.000 1.353 0.086
200.500 1.359 0.091
201.000 1.365 0.093
201.500 1.373 0.093
202.000 1.383 0.091
202.500 1.392 0.087
203.000 1.402 0.081
203.500 1.412 0.073
204.000 1.423 0.065
204.500 1.432 0.055
205.000 1.441 0.045
If the first column may have other than a 3-digit integer part
grep -E '^ *[0-9]+\.[05]00' testdata
Under some circumstances you might need to use [:digit:]
in place of [0-9]
.
And so on.
man grep
is your friend.