bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] [RFC] add support for input/output count of lines


From: Stephane Chazelas
Subject: Re: [PATCH] [RFC] add support for input/output count of lines
Date: Fri, 1 Oct 2004 09:33:19 +0100
User-agent: Mutt/1.5.6i

On Fri, Oct 01, 2004 at 09:48:47AM +0200, Roberto Nibali wrote:
[...]
> 1. get the amount of lines of a file that is grep'd.
> 2. get the amount of lines of where a pattern matched.
> 3. display the matching lines.
[...]

When a task is too complicated for grep, one generally uses
sed or awk, you can't update grep for every single requirement
you have.

> So, here is a 'theoretical trace' of what we do [3 fork()'s]:
> 
> $ wc -l < /var/log/really_big_file
> $ grep -c foobar /var/log/really_big_file
> $ grep foobar /var/log/really_big_file
> 
> With the new patch you can do it with one fork:
> 
> $ grep -j -g foobar /var/log/really_big_file
> 
> or the long opt version:
> 
> $ grep --input-lines --output-line foobar /var/log/really_big_file
> 
> Et voila, it gives your the matching lines and prints two lines to stderr, 
> input_lines=... and output_lines=...

gawk '/foobar/{print; n++} END{print n"/"NR > "/dev/stderr"}'

[that's only my opinion, I'm not a grep developper, I also tend
to think that the "-r", "--include"... options would have best
be suited in a tree walker command as it has nothing to do with
grep's first purpose]

-- 
Stephane

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________




reply via email to

[Prev in Thread] Current Thread [Next in Thread]