Artificial intelligent assistant

Awk regex pattern matching with space I have a file `fruits`: ap ple ora nge pe ar gra pes bro ccoli tom ato ap ache I'd like to make an awk script to check how many fruits are there in the file. I have tried awk -F: '/ap|ora|pe|gra ple|nge|ar|pes/ {sum+=1} END {print sum+0}' fruits and it should return 4, since 4 of their pairs are exact match, but they're returning 5 I think due to `ap ache`. Does the space not register in this case?

The regular expression `ap|ora|pe|gra ple|nge|ar|pes` matches

`ap` or `ora` or `pe` **or** `gra ple` **or** `nge` or `ar` or `pes`

You need to add some grouping to match two separate alternates with space inbetween:


$ awk '/(ap|ora|pe|gra) (ple|nge|ar|pes)/' fruits
ap ple
ora nge
pe ar
gra pes

$ awk '/(ap|ora|pe|gra) (ple|nge|ar|pes)/ {sum+=1} END{print sum}' fruits
4


Note that you don't need to set `-F` to a non-whitespace value since `/pattern/` matches the whole record by default.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy e0752042b0493c3980501105cd967619