SED – Change a strings in the line, only if that line start with

I tried quite a lot of thing and did some search without finding a proper way to do this :

I would like to modify the Apache LogFormat definition on several servers (a lot). So : within httpd.conf, replace this:

   LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
   LogFormat "%h %l %u %t \"%r\" %>s %b" common
   LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

with this:

   LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %T" combined
   LogFormat "%h %l %u %t \"%r\" %>s %b %T" common
   LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O %T" combinedio

without modifying that :

    CustomLog "logs/access_log" common
    CustomLog "logs/access_log" combined

So : I'm looking to s\" com\ %T" com\g', but only for lines containing LogFormat

And I'm starving to do such a thing.



Read more here: https://stackoverflow.com/questions/66332326/sed-change-a-strings-in-the-line-only-if-that-line-start-with

Content Attribution

This content was originally published by redleu at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: