Find directory and create backup

What I'm attempting to do is create a script that will do a search for directories that meet the following criteria:

find . -name "config" -type d

this comes back with:

./dir1/anotherDir/test_dir/config
./dir1/anotherDir/test_dira/config
./dir2/test/test_dir/config

The results could be 10 directories or only 2, but once it comes back with the results I need to change directories to the parent directory of the config directory, then run

tar czf config.tgz config
/dir/to/another/script.sh config.tgz
mv config.tgz_new_file_name /backup/dir

I got most of it down, just the part where I want to CD to the parent directory of each result.

You could try wrapping the find command in a for loop. Not sure which OS or shell you're using but under Bash on Linux:

Save the starting directory:
export startdir="/dir"

Then loop:
for dir in `find . -name 'config' -type d`;do cd ${dir//.\//};cd ..;do your thing;cd $startdir;done

Breakdown:
${dir//.\//} will remove the leading ./ from the find output
cd.. will back up to the parent directory
cd $startdir will return to starting directory for the next iteration through the loop

Hope this helps point you in the right direction.

That works perfectly, now what if the search I'm doing is for a file.

find . -name file.txt;do ....;do my stuff;cd $startdir;done

I understand the {dir//.\//} removes the leading ./, but what would that need to be changed to when I'm searching for a file to remove the file name and the leading ./?

Forgot to mention it but I'm using SLES with Bash shell.