Using Raku (formerly known as Perl_6)
raku -ne '.put if m/car \s motor \: \s (\d**4..*)/ && $0 > 2000;'
OR
raku -ne '.put if .grep(/car \s motor \: \s (\d**4..*)/ && {$0 > 2000});'
Sample Input (thanks to @schrodigerscatcuriosity):
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
car motor: 1
car motor: 100
car motor: 1000
car motor: 2000
car motor: 2001
car motor: 4000
car motor: 9999
car motor: 10000
Sample Output (using either code example, above):
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
car motor: 2001
car motor: 4000
car motor: 9999
car motor: 10000
It looks as though Raku is available for FreeBSD, provided you follow the advice below to install the Rakudo compiler (from source):
https://rakudo.org/downloads/rakudo/source
https://fluca1978.github.io/2020/01/14/RakuOnFreeBSD.html
It even looks as though a Rakudo-Star binary (Rakudo plus core modules) is/was available for FreeBSD:
https://www.tyil.nl/post/2020/06/21/lately-in-raku/
Briefly,the first example using Raku's m/.../
match operator is almost a direct translation of @glenn_jackman's Perl code. For a less 'backslashy' experience, it could be written:
raku -ne '.put if m[ "car motor: " (\d**4..*) ] && $0 > 2000;'
The second example uses Raku's grep
operator. Sometimes it's nice to return matching lines and make non-matching lines blank. You can do this with grep
in Raku like so (numbering all lines as you go):
raku -ne 'put(++$, ". ", .grep: / "car motor: " (\d**4..*)/ && {$0 > 2000} );'
Sample Output:
1. Tue 18 2022 car model: Toyota , car motor: 2001 , car color: blue , year of production: 2018
2. Thu 19 2022 car model: Mercedes , car color: black , year of production: 2012 , car motor: 4000
3.
4.
5. Thu 20 2022 price: 150, car model: GMC , car color: purple , car motor: 3500 , year of production: 2010
6.
7.
8.
9.
10.
11. car motor: 2001
12. car motor: 4000
13. car motor: 9999
14. car motor: 10000
https://raku.org