I prefer Python, but you can't beat
Perl one-liners for doing fairly complicated things in a script or on the command line.
Most of what I had to explain above was regular expression syntax, which is a whole different ball of wax. Don't let regexes scare you away from
Perl.
I highly recommend Jeffrey Friedl's book "Mastering Regular Expressions." I think the current edition is the third. Read the first 80 or so pages and you'll be a regex champ.
ShawnMilo