Per the LQ Rules, please do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and Google searches) and we'll do our best to help. Also, keep in mind that your instructor might also be an LQ member.
The above is our standard homework response......In this case, I think the key thing is to explain what the problem is--including what code you are using and what exactly happens. Also, when you say "only bash", does that mean you are allowed to use standard utilities like AWK and SED?