How can I swap or replace multiple strings in code at the same time?

前端 未结 5 1252
北恋
北恋 2021-01-12 10:32

Given the following code sample:

uint8_t i, in, ni;
i = in = 2; ni = 1;
while (2 == i > ni) in++;

How can I replace i, in, and ni<

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-12 11:03

    > cat foo
    uint8_t i, in, ni;
    i = in = 2; ni = 1;
    while (2 == i > ni) in++;
    > perl -p -i -e 's/\bi\b/inni/; s/\bin\b/inin/; s/\bni\b/i/;' foo
    > cat foo
    uint8_t inni, inin, i;
    inni = inin = 2; i = 1;
    while (2 == inni > i) inin++;
    >
    

    You're welcome to use any other tool supporting regular expressions aside from perl.

提交回复
热议问题