grep question ...
Hi all... I have a file that I want to use this command on: grep "USD" >> US.txt The file has USD twice in it. How do I tell grep to stop after the first find? Thanks, JIM -- Jim Hatridge Linux User #88484 ------------------------------------------------------ WartHog Bulletin Info about new German Stamps http://www.fuzzybunnymilitia.org/~hatridge/bulletin/index.php Viel Feind -- Viel Ehr' Anti-US Propaganda stamp collection http://www.fuzzybunnymilitia.org/~hatridge/collection/index.php
On Wednesday 27 April 2005 11:46 am, James Hatridge wrote:
Hi all...
I have a file that I want to use this command on:
grep "USD" >> US.txt
The file has USD twice in it. How do I tell grep to stop after the first find? Use the -m (or --mcount) command line option: grep -m 1 USD * >> US.txt -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
Hi Jerry et al... Thanks, this was dead on what I needed, JIM On Wednesday 27 April 2005 19:03, Jerry Feldman wrote:
On Wednesday 27 April 2005 11:46 am, James Hatridge wrote:
Hi all...
I have a file that I want to use this command on:
grep "USD" >> US.txt
The file has USD twice in it. How do I tell grep to stop after the first find?
Use the -m (or --mcount) command line option: grep -m 1 USD * >> US.txt -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
-- Jim Hatridge Linux User #88484 ------------------------------------------------------ WartHog Bulletin Info about new German Stamps http://www.fuzzybunnymilitia.org/~hatridge/bulletin/index.php Viel Feind -- Viel Ehr' Anti-US Propaganda stamp collection http://www.fuzzybunnymilitia.org/~hatridge/collection/index.php
On Wednesday 27 April 2005 16:46, James Hatridge wrote:
The file has USD twice in it. How do I tell grep to stop after the first find?
Quoting from 'man grep', in which I searched for "count": -m NUM, --max-count=NUM Stop reading a file after NUM matching lines. If the input is standard input from a regular file, and NUM matching lines are output, grep ensures that the standard input is positioned to just after the last match‐ ing line before exiting, regardless of the presence of trailing context lines. This enables a calling pro‐ cess to resume a search. When grep stops after NUM matching lines, it outputs any trailing context lines. When the -c or --count option is also used, grep does not output a count greater than NUM. When the -v or --invert-match option is also used, grep stops after outputting NUM non-matching lines. Hope that's what you were looking for! -- Bill
participants (3)
-
James Hatridge
-
Jerry Feldman
-
William Gallafent