I'm trying to write a script using the 'find' command and it's -exec option to run a compound command against the files found.
Example:
find . -name "*.conf" -exec cat {} | grep "#" > /tmp/comments.list \;
Of course the above doesn't work. So I experimented for a bit to see if there was some way to group the commands together with ( ) or by quoting the command. But the results weren't useful. So, at this point the only option I have been able to think of is to write a separate script and call it with -exec. But I really would like to have everything in one script. Is it possible to execute a compound command line with -exec? Or am I tilting at windmills?
At a minum you could revise your find to something like this:
find . -name "*.conf" | xargs cat | grep "#" > /tmp/comments.list
This is UUOC. Just use
find . -name "*.conf" -exec grep "#" {} \; > /tmp/comments.list
this works.
find . -name "vg*.*" -exec grep vg {} \;
Or in your case...
find . -name "*.conf" -exec grep "\#" {} \;
Well... I think I should have stated that the example I posted was an example of a type of use for -exec. But it's not the use I am wanting.
I have a need to use 'find' to locate some files. Once those files are found one at a time, I need each to be processed with a long compound command line or possibly multiple commands to write some metadata into the file using variables.
Closer example to reality:
find . -name "*.fil" -exec metafiler -t METADATA1="First Tag" {} -exec metafiler -t METADATA2="Second Tag" {} -exec metfiler -t METADATA3="Third Tag" {} \;
Does that make more sense?
Sometimes I do this....
find . -print | while read filename ; do
echo process $filename
done
Thanks Perderabo! It's a different approach than what I was originally thinking, but it will allow me to accomplish what is needed.