Skip to content

Instantly share code, notes, and snippets.

@antongorshkov
Created April 10, 2016 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antongorshkov/16a89633f7ef67e25a063e3e322781e0 to your computer and use it in GitHub Desktop.
Save antongorshkov/16a89633f7ef67e25a063e3e322781e0 to your computer and use it in GitHub Desktop.
convert pagecount stats to Json messages to be sent to Kafka/MemSQL
#!/bin/bash
for f in *.top; do
f_notop=${f/.top/}
IFS='-' read -r -a array <<< "$f_notop"
date=${array[1]}
hour=${array[2]}
first=0
while read p; do
IFS=' ' read -r -a tokens <<< "$p"
title=${tokens[1]}
count=${tokens[2]}
if [ $first = "1" ]; then
echo {\""title\"":\""$title\"", \""count\"":$count, \""time\"":\""${date:0:4}-${date:4:2}-${date:6:2} ${hour:0:2}:${hour:2:2}:${hour:4:2}\""}
fi
first=1
done < $f > $f.json
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment