grep: Magnificent Bastard
If you're ever playing around with BashPodder on Windows and you find yourself daunted by a single goddamn regex, try to keep this in mind:
grep is a magnificent bastard.
grep is a vital tool for any kind of data processing and a sysadmin's best friend. Naturally, Windows doesn't have it. grep uses regular expressions to find matching lines in a source file.
But grep has a dark secret. It's the -E flag, which the man page states will make grep "use extended regular expressions."
But wasn't grep using regular expressions before? Apparently not.
Broken:
EXTENSIONS="(mp3|torrent|ogg)" if echo "$url" | grep "\.$EXTENSIONS$" > /dev/null
Works great:
EXTENSIONS="(mp3|torrent|ogg)" if echo "$url" | grep -E "\.$EXTENSIONS$" > /dev/null
No comments:
Post a Comment