Generally speaking, for this task I would use either 'awk' or, better yet, Perl.
The task that you are seeking to do is an elementary one for regular expressions, which you see being used here in almost every one of the examples.
Remember this cardinal rule: "do not do a thing already done."
Your purpose should be to accomplish your task, as quickly and as simply (but also as accurately) as you possibly can, while expending the least amount of "unique effort" in the doing of it. So, "there is no reason to write a 'C' program to do this, even if you can." Likewise, IMHO, there's a contra-indication to writing a messy "sed"-based solution that you could not read and understand a week from now without learning it all over again.
No matter what you are doing, remember that thousands of people before you have been asked to do the same thing. They built, debugged, perfected, and then gave-away their tools to the entire community. So, in nearly every case, your modus operandi should not be "to hand craft a solution," but rather, "to find and use a solution that already exists."
|