[ale] Bash question: | in find
Geoffrey
esoteric at 3times25.net
Fri Jan 24 10:55:59 EST 2003
Joe wrote:
> Geoffrey <esoteric at 3times25.net> writes:
>
>
>>I'm trying to figure out what you're trying to do there. I think
>>you're trying to locate the tarball that contains the Xawd library??
>
>
> Yes, in this particular instance. But more generally, I want
> to know how to execute a pipeline (as opposed to a single
> command) in an "-exec" clause in a "find" command.
>
>
>>Why not let tar do the 'grep' for you:
>
>
> Well, because I didn't know tar would do that :-)
>
>
>>for fn in $(find /cdrom/slackware -name '*.tgz' -print); do
>> echo -n $fn " "
>> tar tvzf $fn '*libXaw3d*' 2>/dev/null
>>done |grep Xaw3d
>
>
> Nice. Thanks.
>
>
>>'echo -n' will print the file name without a newline, so the output of
>>tar will be appended to the filename, and the 'grep' on the output of
>>the for loop will print only those lines that contain the Xaw3d, hence
>>all the files that did not contain the file you're looking for will be
>>filtered out.
>
>
> One slight problem: it needs an "echo" *after* the "tar" command,
> otherwise *everything* comes out on one line.
That's wierd. Must be a bash bug, as it doesn't do that under ksh.
Also, there is one possible drawback to the above solution, in that if
tar retrieves more then one file name your output would be something like:
filename first_retrieved_filename
second_retrieved_filename
Thus, the solution is not perfect, but should still work.
>
> Cheers,
>
> -- Joe
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
>
>
--
Until later: Geoffrey esoteric at 3times25.net
The latest, most widespread virus? Microsoft end user agreement.
Think about it...
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale
More information about the Ale
mailing list