find + tar + gzip + uunecode/email --> in one command?

How to search for all files with matching strings -->
find + tar + gzip + uunecode/email them in one command?

I am sure there is a right way to pass list of files to tar, then compress tar file. Then send that as attachment using uuencode in one command.. Can we do that!?

It only gives the first file because you're telling xargs to only give it the first file. from man xargs:

       -l[max-lines]
              Synonym for the -L option.  Unlike -L, the max-lines argument is
              optional.   If  max-lines  is not specified, it defaults to one.
              The -l option is deprecated since the POSIX  standard  specifies
              -L instead.

Remove the -l and it will feed in more.

Be warned, however, that if there are enough files, xargs will be forced to call tar more than once, because it's unable to fit them all into one commandline. when this happens, tar will happily replace the archive it already created with a new one. To avoid this, you must tell tar to append (r, rather than c, option).

This doesn't work for compressed tarballs however -- you can't append to those. You must compress it later.

So:

find . -type f -exec egrep -il 'aaaa|bbbbb|ccccc' {} \; | xargs tar -rvf /tmp/$$.tar

( echo "To:  username@host"
  echo "From:  me@host"
  echo "Subject:  auto-tarball"
  echo
  gzip /tmp/$$.tar | uuencode filename.tar.gz ) | sendmail username@host 

rm -f /tmp/$$.tar

Thanks Corona.

I just noticed a minor but important error in my code:

find . -type f -exec egrep -il 'aaaa|bbbbb|ccccc' {} \; | xargs tar -rvf /tmp/$$.tar

( echo "To:  username@host"
  echo "From:  me@host"
  echo "Subject:  auto-tarball"
  echo
  gzip < /tmp/$$.tar | uuencode filename.tar.gz ) | sendmail username@host 

rm -f /tmp/$$.tar

Without that < , it will just create /tmp/$$.tar.gz and mail a blank, empty attachment.