which shell ? (/bin/sh, bash, etc)
Why can't you use perl ?
You can use awk/sed for that, but those are a *serious* pain (I have not done any awk/sed for for 10 years)
...i tried with perl [...] it is working
Since you ended up using Perl anyway why would you need shell scripting?