Reputation: 13
I'm trying to use sed
to modify a line like below
CustomLog /home/logs/httpd/access_log common
to
CustomLog "|/usr/sbin/rotatelogs /home/logs/httpd/access_log_%m_%d_%Y 86400" combined
I tried sed
replace with text and it didn't work. I'm trying to do this for around 800 files, so need a single command to do this.
Upvotes: 1
Views: 67
Reputation: 246807
sed -i.bak '/CustomLog/{
s# # "|/usr/sbin/rotatelogs #
s/ common$/_%m_%d_%Y 86400" combined/
}' *.conf
Upvotes: 0
Reputation: 21364
This seems to work:
sed 's/\([^ ]*\) \([^ ]*\) \([^ ]*\)/\1 "|\/usr\/sbin\/rotatelogs \2_`date +%m_%d_%Y` 86400" combined/'
Example:
> echo "CustomLog /home/logs/httpd/access_log common" | sed 's/\([^ ]*\) \([^ ]*\) \([^ ]*\)/\1 "|\/usr\/sbin\/rotatelogs \2_`date +%m_%d_%Y` 86400" combined/'
Upvotes: 1