tags:

views:

54

answers:

2

I want to replace every instance of int in a very large codebase with int32_t, for portability reasons. I have unsuccessfully tried :

 sed s/'\bint\b'/' int32_t '/g 

and it fails to match instances where the int is the first thing on the line. I am completely at a loss for how to make it match then.

Any ideas?

+1  A: 
s/'^int\b'/'int32_t\b'/g

should match those beginning of the line cases, assuming by beginning of the line you mean the very first thing on the line. If your problem is caused by tab character preceding the int, run the code through expand to turn tabs into spaces then your original expression will work.

Amardeep
+2  A: 

Your pattern is right, works for me, including start of line case :

sed 's/\bint\b/\ int32_t\ /g' file

(possibly the quotes?)

Steve B.
It seems to me that the version of sed in Mac OS X is what's causing this problem, as a Linux version works perfectly. Time to get compiling!
Alex