gunzip *.gz
for file in ./*; do cat $file >> log.txt ; done
查询命令
cat min.log |awk '{print $1}'
cat min.log |awk '{print $2}'
grep -w "200" log.txt |awk '{if($9=="206") print $0}' > 200log.txt
grep -w "200" log.txt
统计命令
cat log.txt |awk 'BEGIN {size=0} {size=size+$11} END{print "endsizeis",size/1024/1024,"M"} '
cat [$Log_Txt] | awk '{print $3}' |sort|uniq -c|sort -nr |head -10
cat min.log | awk '{print $6}' |sort|uniq -c|sort -nr |head -100 >a.log
cat 5-15.log | awk '{print $6}' |sort|uniq -c|sort -nr |head -100 >refer-5-14.csv
cat log.log | awk '{if($6 ~ ".m3u8") print $6}' |sort|uniq -c|sort -nr |head -100 > top1000.txt
cat 5-14.log | awk '{if($6 ~ ".m3u8") print $6}' |sort|uniq -c|sort -nr |head -100 > top1000.txt
cat 5-15.log | awk '{if($6 ~ ".m3u8") print $6}' |sort|uniq -c|sort -nr |head -100 > top100.csv
cat 5-16.log | awk '{if($6 ~ ".m3u8") print $6}' |sort|uniq -c|sort -nr |head -100 > top100.csv
cat 5-19.log | awk '{if($6 ~ "clubapp.wuyang-honda.com") print $6}' |sort|uniq -c|sort -nr |head -100 > wuyan-5-19.csv
#url path中包含/557/
cat 5-15.log | awk '{if($8 ~ "/557/") print $8}' |sort|uniq -c|sort -nr |head -100 > top100.csv
# 输出全段
cat 5-15.log | awk '{if($8 ~ "/557/") print $0}' |sort|uniq -c|sort -nr |head -10000 > 557_top10000-5-15.csv
cat 5-16.log | awk '{if($8 ~ "/557/") print $0}' |sort|uniq -c|sort -nr |head -10000 > 557_top10000-5-16.csv
cat 5-18.log | awk '{if($8 ~ "/557/") print $0}' |sort|uniq -c|sort -nr |head -10000 > 557_top10000-5-18.csv
cat 5-19.log | awk '{if($8 ~ "/557/") print $0}' |sort|uniq -c|sort -nr |head -10000 > 557_top10000-5-19.csv
查找指定时间的内容输出到新文件
#-i忽略大小写 -F忽略正则
grep -i -F '26/Aug/2024:06:13' access-2024-08.log > 613.log
#错误grep: access-2024-08.log: binary file matches
因为文件含有特殊的字符,使用--binary-files=text强制忽略
grep --binary-files=text -i -F '26/Aug/2024:01:38' access.log >138.log
#查询包含指定域名的日志到,输出到新文件
grep 'study-cdn\.jobpi\.cn' 925.log > 9251.log
# 查询状态到504
grep -w "504" 9251.log > 9252.log