Using grep/awk to find/print certain pattern in a text file reddit / freebsd ---------------------------------------------------------------------- lifty_hanz · 2022-01-19 20:45 Assume that i have a text file containing the following 5 lines: Tue 18 2022 car model: Toyota , car motor: 2001 , car color: blue , year of production: 2018 Thu 19 2022 car model: Mercedes , car color: black , year of production: 2012 , car motor: 4000 Thu 20 2022 used: yes , car motor: 1999 , car model: Mercedes , car color: black , year of production: 2012 Thu 20 2022 car model: Kia , car motor: 1500 , car color: red , used: no , year of production: 2010 Thu 20 2022 price: 150, car model: GMC , car color: purple , car motor: 3500 , year of production: 2010 i'm looking for grep/awk (or other utility that's available on freebsd 11) that will find/print every line where the following condition evaluated TRUE: Phrase "car motor:" followed with numerical value greater than 2000. Such grep/awk is expected to find/print the following lines from the text file: Tue 18 2022 car model: Toyota , car motor: 2001 , car color: blue , year of production: 2018 Thu 19 2022 car model: Mercedes , car color: black , year of production: 2012 , car motor: 4000 Thu 20 2022 price: 150, car model: GMC , car color: purple , car motor: 3500 , year of production: 2010 ---------------------------------------------------------------------- gumnos · 2022-01-19 20:51 Grep doesn't do so well with numerical comparisons, so I'd reach for `awk` here: $ awk -F' *[,:] *' '{for (i=1;i 2000){print; next}}' ---------------------------------------------------------------------- cmjrees · 2022-01-20 19:38 Numerical comparisons normally yes, but grep 'car motor: [2-9][0-9][0-9][0-9][0-9]' should work perfectly in this case.