text replace question for Unix masters
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
Close this Gamedev account, I have outgrown Gamedev.
Take a look at the 'sed' command, or 'perl -e'. A quick google search shows many possibilities.
<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>
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);"
sed 's/\(Delete \[\]\)\(.*\);/delete_array(\2);/g' $1 | sed 's/\(Delete\)\(.*\);/Delete(\2);/g' | sed 's/delete_array/Delete_array/g'
but atleast I learned sed better :)
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);"
sed 's/\(Delete \[\]\)\(.*\);/delete_array(\2);/g' $1 | sed 's/\(Delete\)\(.*\);/Delete(\2);/g' | sed 's/delete_array/Delete_array/g'
but atleast I learned sed better :)
Close this Gamedev account, I have outgrown Gamedev.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement