Skip to content

re: How Unix programmers at restaurants search menus for their favorite plate VIEW POST


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.


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.


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


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.

code of conduct - report abuse