Delete line based on count of specific character

I'm looking for what I hope might be a one liner along these lines:

sed '/a line with more than 3 pipes in it/d'

I know how to get the pipe count in a string and store it in a variable, but I'm greedy enough to hope that it's possible via regex in the /.../d context. Am I asking too much? Thanks in advance!

Try:

awk -F\| 'NF<5' file

Hi tiggyboo,

One way using perl:

$ perl -ne 'print if tr/|/|/ < 4' infile
sed '/\(|.*\)\{4\}/d' file
sed '/|.*|.*|.*|/d' file

A minor tweak to Scrutinizer's suggestion saves the regular expression engine some work (not that it'll make a difference with ordinary files):

sed '/\(|[^|]*\)\{4\}/d' file

Regards,
Alister

Thanks a bunch for the responses folks! Very instructive to see the different options. I'm looking forward to the day when some of these regex type solutions become more intuitive to me :-).

Regards,
Al