DEV Community

Discussion on: How Unix programmers at restaurants search menus for their favorite plate

Collapse
 
moopet profile image
Ben Sinclair • Edited

I've been reading the thread about this on /r/programming (how circular!) and they're mostly (deliberately?) missing the point and trying to optimise it rather than to see it as a demonstration of pipes.

cough

grep -q 'shrimp.*$[0-9]\.' menu.txt && echo "Available" || echo ":("

EDIT: changed \d shortcode for [0-9] so it'll work with BSD and GNU grep.

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
kenbellows profile image
Ken Bellows • Edited

That's what this bit at the end is for:

$[0-9]\.

That bit of the regex will only match on a line that contains a dollar sign ($), a single digit ([0-9]), and a literal dot (\.). So "$2.99" will match, but "$12.99" won't, because there are two digits between the dollar sign and the dot.

Collapse
 
moopet profile image
Ben Sinclair

Try it.