bug-grep
[Top][All Lists]
Advanced

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

Re: find + sh + grep


From: Eric Blake
Subject: Re: find + sh + grep
Date: Tue, 25 Oct 2011 10:36:38 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110928 Fedora/3.1.15-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.4 Thunderbird/3.1.15

On 10/24/2011 12:14 PM, Eric Blake wrote:
find -type f -name bp_fs.h \
-exec sed -n '1,5{/\$Header:/q1};6q' {} \; -print

Alas, I don't know of any way to use -exec ... {} + for fewer processes,
even with sed.git with the -s option and the new F command, because I
don't have enough sed expertise to write a script that outputs the
filename of each of its multiple input files exactly in the case where
the first five lines do not contain a regex match.

Aha, I realized how to do it, using the 'N' operator. This spawns as few processes as possible, while still giving the same answer (assuming, of course, that you are using sed.git or the not-yet-released sed 4.2.2):

find -type f -name bp_fs.h \
 -exec sed -sn '1{N;N;N;N;/$Header:/bl;F;:l}' {} +

It's still not as efficient as I'd like (I don't know any way to make sed avoid reading the rest of the file, and just skip to the next, once it has finished its analysis of the first 5 lines). But efficiency within sed is much less of a problem than spawning one sed process per file.

--
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org



reply via email to

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