Hi Tim,

On Tue, Oct 23, 2012 at 8:52 PM, Tim Bird <tim.b...@am.sony.com> wrote:
> On 10/23/2012 11:42 AM, Geert Uytterhoeven wrote:
>> On Tue, Oct 23, 2012 at 8:27 PM, Thomas Petazzoni
>> <thomas.petazz...@free-electrons.com> wrote:
>>>>> find . -exec fgrep -H "$1" {} \;
>>>>>
>>>>> but with lots and lots of other qualifiers.  You can see a usable
>>>>> version at
>>>>>
>>>>> https://www.ridgerun.com/developer/wiki/index.php/Tip_of_the_day#finds_-_find_a_string_in_common_text_files
>>>>
>>>> This looks useful.
>>>>
>>>> I do something similar with the kernel.  I have
>>>> a small one-line wrapper called armcgrep, which greps only the files
>>>> in the arch/arm section of the kernel source tree, and only those
>>>> with filenames matching the pattern "*.[chS]".  Once things
>>>> are in the page cache, it works pretty fast.
>>>>
>>>> 'finds' looks similar, but it also omits some areas, and includes
>>>> things like Kconfig and others.  I need to mentally digest all
>>>> the 'find' magic in it...
>>>
>>> Note also that you can use 'git grep', that will only grep the source
>>> files that are under version control, skipping all object files and
>>> other generated files you may have in your tree, if you're not doing
>>> out of tree builds. I use 'git grep' routinely.
>>
>> Yeah. For Tim's use case:
>>
>>     git grep <pattern> -- "arch/arm/*.[chS]"
>
> Actually I mis-stated the case a bit.  I'm searching the whole kernel
> tree, but only including one architecture directory, arch/arm, in the search.
> This is primarily to omit extraneous matches for other architectures (which I
> might not be interested in at the moment).  The way the kernel is written,
> there are often arch-specific functions or structures that show up multiple
> times if you don't filter down to one arch.
>
> Here's my solution (armcgrep):
>
> #!/bin/sh
> find . -path "./.pc" -prune -o -name "*.[chS]" | xargs egrep "$1" | grep -v 
> arch/[^a] | grep -v arch/a[^r]
>
> I know there must be a simpler way to filter out non-arm arches than with
> two "grep -v"s (anyone??), but it works... :-)

In any case, you want to do those 2 greps _before_ the xargs, so you're egrep
doesn't do useless processing on the files you're not interested in.

> I have to prune out .pc because I'm using quilt and would otherwise get a lot
> of matches in that sub-directory.

Hence you can replace the find part with

    git ls-files "*.[chS]"

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- ge...@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
_______________________________________________
Celinux-dev mailing list
Celinux-dev@lists.celinuxforum.org
https://lists.celinuxforum.org/mailman/listinfo/celinux-dev

Reply via email to