Sed replace over newlines?
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 ma开发者_StackOverflowke it match then.
Any ideas?
Your pattern is right, works for me, including start of line case :
sed 's/\bint\b/\ int32_t\ /g' file
(possibly the quotes?)
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.
精彩评论