grep usage - exit after first occurrence

Hi,

Is there any way of using grep (this may be done in awk, not sure?) that I can stop grep'n a file once I have found the first occurrence of my search string. Looking through grep man pages
-q will exit without printing the lines after the first match, but I need the output.

I have looked at awk but am not finding what i require.

Any ideas,

Cheers and beers,

Neil

How about something like

while read line; do
  echo $line | grep "searchstring"
  if [ "$?" -eq "0" ]; then
     break
  fi
done < input_file

Cheers
ZB

grep -m 1 <expression> <file_name>

hope it will work.
cheers

-m is fine for GNU grep, but isn't portable across older (or even new vendor supplied) grep implementations.

Cheers,
ZB

sed:

sed -n '/pattern/{p;q;}' filename

You could pipe the results of your grep through head, it would look something like this:

grep <patern> <file> | head -1

if your file is incredibley large this may not be what you want, but if all you want to know is the first thing that grep found, and time wont be an issue, then this may be the most simple...