Last active
November 27, 2017 19:45
-
-
Save ntjn/6be8f4eaaa03d2669e40537ac3fc57fc to your computer and use it in GitHub Desktop.
This file contains 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/bash | |
extractDate() { sed 's/[^\.]*\.//'; } | |
toStamp() { date --date="$1" +%s; } | |
# [$1, $2): bound | |
# $3 current date | |
function isBetween() { | |
[[ `toStamp $1` -le `toStamp $3` ]]&&\ | |
[[ `toStamp $2` -gt `toStamp $3` ]]&&\ | |
true||\ | |
false | |
} | |
function isFileBetween() { | |
} | |
lowerDateBound="someDate" | |
upperDateBound="someDate" | |
FILES=`ls C:/Users/userid/Desktop/UAT_log_files/` | |
for f in $FILES;do | |
if $(isBetween `extractDate $lowerDateBound` `extractDate upperDateBound` `extractDate $f` ); then | |
LOG="$f.temp" | |
CSV="$f.csv" | |
echo "Processing $f file.." | |
sed 's|[[[,]||g' $f >> $LOG | |
echo "Line Number,clientip,requestid,user,date,request,method,response,bytes,request_time,referrer,HTTP_Client & session_id" > $CSV | |
< $LOG awk '{if(length($13)>100) $13=substr($13,1,100);print NR-0 "," $1","$2","$3","$4","$6","$7" "$8" "$9","$10","$11" , " $12", " $13" , " $14" " $15" " $16" " $17" " $18" " $19" " $20" " $21" " $22" " $23" " $24" " $25" " $26" " $27" " $28}' >> $ | |
fi | |
#rm $FILES.temp | |
done | |
echo "clientip , requestid , user , date , request , method , response , bytes , request_time , referrer , HTTP_Client & session_id " > $FILESMainlog.csv | |
cat $FILES.csv >> Mainlog_temp.csv | |
rm .csv | |
echo "Deleting the temporary files now.." | |
rm $FILES.csv | |
echo "fixing the date time format" | |
awk -f redate.awk mainlog_temp.csv>mainlog.csv | |
sed 's/--date ::/date/g' mainlog.csv > new.csv ; mv new.csv mainlog.csv | |
rm mainlog_temp.csv | |
echo "Done! The file mainlog.csv has been created in the current directory" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment