text replace question for Unix masters

Recommended Posts

Barring opening up an editor and doing search replace, I was hoping that a nix master could tell me how to do the following on set of files: I would like to replace: "Delete ptr;" with "Delete(ptr)" and "Delete []ptr;" with "DeleteArray(ptr)" where ptr can be any C++-identifier... I was thinking of somehow using sed, but then I was not too sure how to go about it... [lex/flex are also an option, but they seem like overkill for such a simple operation] Best Regards

Share on other sites
Take a look at the 'sed' command, or 'perl -e'. A quick google search shows many possibilities.

Share on other sites
I did look at sed, but as I am quite unfamilary with it, I was not too sure how to manage, I though: replace "Delete []ptr;" with "Delete_array(ptr)", so the string to replace would be: "Delete []"*";", and maybe the correct sed command would then be, I thought:

sed 's/Delete *;/Delete_array(&);/' < InFile.cpp > OutFile.cpp

but that did not do anything... but alas I realized that I should be using .* and not *, at the end of the day 3 sed commands piped together did the full job of replacing "Delete ptr;" with "Delete(ptr)" and "Delete []ptr;" with "Delete_array(ptr);"

• Partner Spotlight

• Forum Statistics

• Total Topics
627642
• Total Posts
2978354

• 10
• 12
• 22
• 13
• 33