first_page the funky knowledge base
personal notes from way, _way_ back and maybe today

bash Script: a rough draft that splits a monthly Apache web log into days with zgrep

#!/bin/bash

file=$2 month=$1 year=date +%Y

echo "Searching $file for days in $month..."

for day in {1..31} do query=$(printf "\\[%02d/%s/%s" $day $month $year) outfile=$(printf "out_%s_%s_%02d.gz" $year $month $day) count=$(zgrep -c "$query" "$file") if [ $count -gt 0 ] then printf "Found %d entries for %s/%02d/%s...\\n" $count $month $day $year zgrep "$query" "$file" | gzip >> "$outfile" fi done

exit 0

mod date: 2008-01-02T19:59:34.000Z