Recursively UNTARing and then TARing back

I've just finished writing a shell script that searches for a string recursively in all text files and replace them with another string. Now, all these files come from a location nested deep within some TAR files which are inside another mother TAR.

To make my script work, we had been UNTARing all these TAR files, running the search/replace, then TARing them back. How do I automate this step too by a shell script?

What Operating System do you have?
What Shell do you prefer?
What do you type when doing the job manually?

I usually use UNIX or Linux. And bash is what we use mostly. When we do this manually, we type

tar -xf tarfilename.tar

to extract the TAR files, and then after running the script to search/replace, we go back to every unextracted file's path and then type

tar -cf tarfilename.tar foldername/

Presumably you type more than just two "tar" lines.

Well, a couple of tar lines, for each nested TAR file. Once everything is extracted, we run our script. Once it replaces everything, we put back everything into TARs.

I give up.

:eek::frowning: