#!/bin/bash if [ $# -ne 1 ]; then echo Usage: $0 Log file exit 1 fi if [ ! -f $1 ]; then echo File $1 seems not to exist exit 1 fi grep ' \- \- ' $1 > $1.tmp mv -f $1.tmp $1 declare -A months months[Jan]=01 months[Feb]=02 months[Mar]=03 months[Apr]=04 months[May]=05 months[Jun]=06 months[Jul]=07 months[Aug]=08 months[Sep]=09 months[Oct]=10 months[Nov]=11 months[Dec]=12 for i in Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec; do echo "s/$i/${months[$i]}/" >> /tmp/$$.sed done sed -i -f /tmp/$$.sed -e 's/- - \[\([0-9]\{2\}\)\/\([0-9]\{2\}\)\/20\([0-9]\{2\}\):/20\3-\2-\1 /g' -e 's/ [+-][0-9]\{4\}]//' -e 's/ - / 0 /' $1 rm -f /tmp/$$.sed # Remove hits from IPv6 addresses: egrep -v "^.{4}:" $1 > $1.tmp mv -f $1.tmp $1 # Remove hits from robots: egrep -v '(Yandex|Baidu|Google|Slurp|bingbot|Sogou|DotBot|msnbot|MJ12bot|Exabot|Twitterbot|omgilibot|Kraken|Applebot|BuzzSumo|bitlybot|AhrefsBot|rogerbot|Spiderbot|linkdexbot|Cliqzbot|Buzzbot|trendictionbot|Bot|Crawler|Yeti|Mediatoolkitbot|datagnionbot|ISSbot|linkapediabot|Slack|NewsNow|ltx71)' $1 > $1.tmp mv -f $1.tmp $1