Last active
March 9, 2017 14:09
-
-
Save nehaljwani/5946464 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#+Author: Nehal J Wani | |
#CONVERT SQUID ACCESS.LOG TO HUMAN READABLE | |
cat $1 | awk '{print $1}' | sort | uniq -c > STAMP | |
cat STAMP | awk '{print $1}' > COUNT | |
cat STAMP | awk '{print $2}' > STAMP_1 | |
rm -f STAMP | |
while read line ; do echo `date -d @"$line"` ; 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((' '.join(f2[i*6:(i+1)*6])+'\n')*int(f1[i])); | |
" | |
rm -f COUNT TIMESTAMP | |
cat $1 | awk '{{for(i=2;i<NF;i++)printf "%s ",$i}{printf "\n"}}' > REST | |
paste -d' ' ROW1 REST > $1_FINAL | |
rm -f ROW1 REST |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<stdlib.h> | |
#include<time.h> | |
int main(int argc, char **argv) { | |
if (argc < 2) { | |
printf("Usage: %s access.log\n", argv[0]); | |
exit(-1); | |
} | |
FILE *fp = fopen(argv[1], "r"); | |
char *buf = (char *) malloc(sizeof(char) * 10000); | |
char timestamp[32]; | |
while (fscanf(fp, " %[^\n]", buf) != EOF) { | |
char *iter = buf; | |
while (*iter != ' ') | |
iter++; | |
*iter = '\0'; | |
struct tm ts; | |
time_t time = atof(buf); | |
ts = *localtime_r(&time, &ts); | |
strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", &ts); | |
printf("%s %s\n", timestamp, iter + 1); | |
} | |
free(buf); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment