Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

I need to write a string to replace all non-portable data types to portable types.
e.g int to int32_t

I made the below command to replace int

find . -type f \( -name "*.cpp" -or -name "*.cc" -or -name "*.h" \) -exec sed -i 's/\bint\b/int32_t/g' {} +

But it is also replacing cases inside comment section like int-class etc
I do not want to replace cases if it is inside comment or if int is immediately preceded by any special character like int- etc.

Could you please anyone let me know the solution

What I have tried:

find . -type f \( -name "*.cpp" -or -name "*.cc" -or -name "*.h" \) -exec sed -i 's/\bint\b/int32_t/g' {} +
Posted
Comments
Richard MacCutchan 31-May-16 11:29am    
I cannot think of a simple way to do that in one pass. You may need to run the find a second (or even third) time, converting all the invalid items back to int.
Sergey Alexandrovich Kryukov 31-May-16 21:07pm    
It's not "portable" vs "unportable", this is implementation-dependent int vs implementation-independent. What is more portable is a "philosophical question". Now, the replacement you have to perform is somewhat risky. Make sure you keep the latest version of all files in your Revision Control system. (If you don't use any Revision Control system, consider you are not really doing software development. :-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900