Delete lines that contain 3 or more words?

How can I delete lines that contain 3 or more words?
I have a file, old.txt, that has multi-word phrases in it and I want to remove the lines with 3 words or more and send the output to new.txt.

I've tried the following using sed but it doesn't seem to work:

sed '/(\b\w+\b){3,}/d' old.txt > new.txt

Any help would be appreciated.

 sed -n -e "s/^[ ]*[^ ]* [^ ]* [^ ]*[ ]$/&/p file.txt > new.txt

Hi , many ways to do it, other with sed:

> sed -e "/^[^ ]\{1,\} \{1,\}[^ ]\{1,\} \{1,\}[^ ]\{1,\}/d" file     

> awk 'NF<=2' file 

Thanks. Seems like awk is easier for this task. :slight_smile:

Depends on your definition of word,
with GNU grep it could be something like this:

grep -E '(\w+\b\W+){2}\b\w+' data>new_data

Hi.
I've learned something new - I didn't know that awk had an implied print.