alexgolec
alexgolec

Reputation: 28282

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 make it match then.

Any ideas?

Upvotes: 1

Views: 264

Answers (2)

Amardeep AC9MF
Amardeep AC9MF

Reputation: 19064

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.

Upvotes: 1

Steve B.
Steve B.

Reputation: 57333

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

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

(possibly the quotes?)

Upvotes: 2

Related Questions