Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nehaljwani/5942908 to your computer and use it in GitHub Desktop.
Save nehaljwani/5942908 to your computer and use it in GitHub Desktop.
#!/bin/sh
#+Author: Nehal J Wani
#To Convert logformat squid %tl %6tr %>a %Ss/%03>Hs %<st %rm %ru %un %Sh/%<A %mt to Default
cat $1 | awk -v FS='/' '{ printf "06/%s/",$1; printf "%.4s %s\n",$3, substr($3,6,9)}' > STAMP
cat STAMP | uniq -c | awk '{{ print $1 > "COUNT"} {print $2,$3 > "STAMP_1"}}'
rm -f STAMP
while read line ; do echo `date -d "$line" "+%s"`".000" ; done < STAMP_1 > TIMESTAMP
rm -f STAMP_1
python -c "
f1=open('COUNT').read().split();
f2=open('TIMESTAMP').read().split();
f3=open('ROW1','w');
size=len(f1);
for i in range(size): f3.write((f2[i]+'\n')*int(f1[i]));
"
rm -f TIMESTAMP COUNT
cat $1 | awk '{for(i=3;i<NF;i++) printf "%s ",$i; printf "\n"}' > REST
paste -d' ' ROW1 REST > ${1}_FINAL
rm -f ROW1 REST
@chacal22
Copy link

chacal22 commented Jul 7, 2017

genius , greetings from argentina

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment