[clue] Piping, xargs, find, grep and such
Leif
leif-clue at kurnl.net
Mon Sep 17 07:41:12 MDT 2012
Here is a general purpose zsh/bash function for doing tasks such as this.
FilesHaving () {
local command=$1
shift
local i
local output
for i in $@
do
output=`eval $command`
if [ -n "$output" ]
then
output=`echo $output | sed "s@^@$i: @"`
echo $output
fi
done
}
Most often I use it for finding symbols in libraries.
FilesHaving 'nm $i | grep strftime' /usr/lib/*.a 2> /dev/null
Some trickery is needed where find/xargs is required.
-Leif
On 09/16/2012 09:07 PM, David L. Anselmi wrote:
> jacob wrote:
>> puts "#{ARGF.filename}:#{output}" if output =~ /pattern/
> Yeah, when you're dealing with something modern like Perl or Ruby it may not make sense to do work
> in external programs. They handle command line args easily and do pattern matching as well and as
> simply as grep.
>
> So you have to decide whether Jacob's suggestion is more elegant than the ones I suggested, which
> will depend on whether it's more useful to adapt your output to work with grep or to add flexibility
> to work either way.
>
> Dave
> _______________________________________________
> clue mailing list: clue at cluedenver.org
> For information, account preferences, or to unsubscribe see:
> http://cluedenver.org/mailman/listinfo/clue
More information about the clue
mailing list