I'll also say this: don't send a shell script (for any shell) to do
a Camel's job.
Shell scripts (with the slight exception of the Korn shell, which for some reason
does embed a full programming language) were not really designed for "heavy duty programming." But all of them
do support the
#! ("shebang...") construct, which allows the script to be written in
any language. And there are many of them at your fingertips: Perl, PHP, Ruby, Python, and many more.
The task that you describe, while not entirely trivial, is the work of a simple Perl program that would be no more than a hundred lines or so, if that. (No, I'm not going to write it for you.)