[CentOS] awk global replacement only after keyword

m.roth at 5-cent.us m.roth at 5-cent.us
Fri Mar 26 13:37:42 UTC 2010


>>Depends on how you define "one-liner."  Something like this might work:
>>
>>{ if index($0, PATTERN) != 0 {FOUND = 1;}; if (FOUND != 0)
>>{subst(REPLACE_THIS, WITH_THIS, $0); }
>>
>>You'd want to reverse the order of the two statements if the
>>replacement is only to occur after the pattern is found.
>
> Cool, I'll give it a whirl tomorrow! I do want to replace all
> occurrences only after the keyword

When you say "after", do you mean
blah, blah
blah, blah
yadda, yadda, keyword, to-be-replaced

or do you mean
blah, blah
blah, blah
yadda, yadda, keyword,
to-be-replaced
also-to-be-replaced?

         mark "awk 'r' us"





More information about the CentOS mailing list