Reputation: 3
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.
Upvotes: 0
Views: 193
Reputation: 12877
You would be better served using a dedicated solution such as Ansible for this but using sed, you could do the following:
sed -i '/^LogFormat/s/" combined.*$/ %T&/' httpd.conf
Search for all lines starting with "LogFormat" and then substitute double quotes, space and "combined" for a space, "%T" and the pattern identified.
Upvotes: 1