grep a specific amount of occurrence

hey , i m trying to figure out how to do the following :

i got a text file the looks like so:

 
1031
1031
1031
1031
1031
1031
1031
1031
16500
16500
16500
16500
1031
1031
1031
1031
1031
16500
16500
16500

i want to grep a specific amount of a value , for example
grep of "16500" for 3 occurrences the output will be:

16500
16500
16500

note that this is a part of a table i dont want to just print the value - X times.

please advise
thanks.

Hi.

For GNU grep:

       -m NUM, --max-count=NUM
              Stop reading a file after NUM matching lines.
-- excerpt from man grep, q.v.

Best wishes ... cheers, drl

If you do not have GNU grep, you can do it with awk (the specifics depend on what your data looks like).

Regards,
Alister

egrep -i '16500' | wc -l

i think it will do it.

This will count the occurrences of "16500" but not limit the result set to a specific number of them. There is the "-c" switch of grep for that, btw..

grep <regexp> | head -<number>

Will give you the first <number> of hits, while

grep <regexp> | tail -<number>

will give you the last <number> of hits.

I hope this helps.

bakunin