Skip to content

Instantly share code, notes, and snippets.

@yerstd
Created May 10, 2018 13:27
Show Gist options
  • Save yerstd/235b602353ccfe44ea93e4b1d64116d2 to your computer and use it in GitHub Desktop.
Save yerstd/235b602353ccfe44ea93e4b1d64116d2 to your computer and use it in GitHub Desktop.
#!/bin/bash
logfile=big-log.txt
keyStr=""
valStr=""
awk -F{ '{print $2}' $logfile | awk -F, '{
for (i=1;i<=5;i++){
print $i;
}
}' | awk -F: '{print $1,$2,NR}' | while read key val n;do
#echo "$n : $key => $val"
if [ `expr $n % 5` == 1 ];then
keyStr=$key
valStr=$val
else
keyStr="$keyStr,$key"
valStr="$valStr,$val"
echo $keyStr
echo $valStr
fi
if [ `expr $n % 5` -eq 0 ] && [ $n > 0 ];then
printf "insert into game_answer_history (%s) values (%s)\n" $keyStr $valStr >> /tmp/test.sql
keyStr=""
valStr=""
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment