Tuesday, April 10, 2007

grep!

grep has a -q (quiet) mode.

This is GREAT for use in scripts. If the string you're grepping for gets a match, it returns 0.

No fiddling with comparison operators for your if statements!

#!/bin/sh

if grep -q needle haystack.txt
then
echo "I found a needle!"
else
echo "No needles here..."
fi

No comments: