# text replace question for Unix masters

This topic is 3936 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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);"

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
16
5. 5

• 14
• 29
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631775
• Total Posts
3002275
×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!