Maybe OT - Grepping the locate command
John McCabe-Dansted
gmatht at gmail.com
Wed Mar 3 11:08:27 GMT 2010
On Wed, Mar 3, 2010 at 6:46 PM, Martin Pitt <martin.pitt at ubuntu.com> wrote:
> donn [2010-03-03 12:39 +0200]:
>> I would like to search through the *contents* of the files returned by
>> locate. So far I have not had much luck.
...
> locate *.ods | xargs grep blah
> ls | xargs cat
>
> will do what you want.
Only Donn also wants to unzip them, so we need something a bit longer like.
locate *.ods | while read f ; do unzip -p $f | grep BLAH > /dev/null
&& echo $f ; done
(I've added the > /dev/null as the grep output on ods files tends to
be huge and ugly, it can be removed).
If this will be used regularly you can type:
function search_ods {
locate *.ods | while read f; do
unzip -p $f | grep --color=auto "$1" > /dev/null && echo $f;
done
}
so that henceforth you can just type
search_ods BLAH
So that the search_ods function is automatically added to terminal
shells opened later you can append the above function to ~/.bashrc.
(To make this on topic, let me say "try that with CMD.EXE" ;)
--
John C. McCabe-Dansted
More information about the sounder
mailing list