[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to print both matched and non matched lines?
From: |
Eric Blake |
Subject: |
Re: How to print both matched and non matched lines? |
Date: |
Tue, 22 Nov 2011 09:05:42 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110930 Thunderbird/7.0.1 |
On 11/21/2011 10:47 PM, Peng Yu wrote:
> Hi,
>
> I use --color=auto, so that I can distinguish nonmatched lines from
> matched lines by looking at the colored text if the non matched lines
> is shown. But I don't see an option to allow me show all lines. Would
> you please let me know if there is such an option if I miss anything
> in the man page?
Use -C to expand the context sufficiently large to show all lines. For
example,
grep --color=auto -C$(wc -l < file) pattern file
is guaranteed to show the entire file, as long as there is at least one
match for pattern.
Hmm, this points out a probable optimization bug in grep, that we should
consider fixing. This test is done in grep.git:
$ time src/grep -C$((1<<20)) 'as is' README > /dev/null
real 0m0.007s
user 0m0.002s
sys 0m0.005s
$ time src/grep -C$((1<<25)) 'as is' README > /dev/null
real 0m0.081s
user 0m0.077s
sys 0m0.004s
$ time src/grep -C$((1<<30)) 'as is' README > /dev/null
real 0m0.759s
user 0m0.755s
sys 0m0.004s
so why does making the context at order of magnitude larger make the
computation take an order of magnitude more time in computing identical
results?
--
Eric Blake address@hidden +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature