perl - Repalce IP address in Apache Log -
i have apache logs generated in format:
192.168.1.125 - - [25/may/2014:03:43:10 +0000] "post /myapp/getrequest?ip=88.125.88.88 http/1.1" 200 22 "-" "11.0"
i wish swap first ip in files second i.e. swap 192.168.1.125 88.125.88.88. line should this:
88.125.88.88 - - [25/may/2014:03:43:10 +0000] "post /myapp/getrequest?ip=192.168.1.125 http/1.1" 200 22 "-" "11.0"
reason being: want use awstats geolocation ip address in first column. way now, ip address of proxy server. customer's ip in part of request url.
my system linux machine. not perl or sed, googling, came close to:
perl -pe 's/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b -/xxxxxxxxxxx -/' access_log
i not sure put xxxxxxxxxxx. ideas how can done?
perl -pe's/^(\s+)(\s.*?[?&]ip=)([\d.]*)/$3$2$1/' access_log
non-swapping version:
perl -pe's/^\s+(\s.*?[?&]ip=([\d.]*))/$2$1/' access_log
usage:
perl -pe'...' access_log > fixed_access_log perl -i~ -pe'...' access_log # edit "in-place" backup perl -i -pe'...' access_log # edit "in-place" without backup
Comments
Post a Comment