小蚂蚁 发表于 2021-10-2 11:12:00

windows下Nginx日志处理脚本

运行说明:20120917.txt是需要分析的日志,last.csv是统计结果(使用execl打开,方便统计、排序)。

1. [文件] awk.zip

2. [图片] 运行截图.jpg


3. [图片] 运行结果


4. [代码]存为bat双击打开即可


@echo off
setlocal ENABLEDELAYEDEXPANSION
rem 将IP提取到ip.txt文件
awk.exe "{a[$1]+=1;}END{for(i in a){print i;}}" 20120917.txt> ip.txt
rem 逐行读取ip.txt文件中的IP,并调用youdao.com的ip地址源查询接口
del result.txt
del last.txt
del last.csv
for /f "delims=" %%k in (ip.txt) do (
set /a b+=1
wget-1.10.2.exe "https://www.youdao.com/smartresult-xml/search.s?type=ip&q=%%k" --output-document=temp.xml>nul2>nul
echo 正在处理%%k
for /f "delims=" %%i in (temp.xml) do (
set /a num+=1
set str=%%i
set str1=">%%k,!str!<"
if !num! equ 5 (echo !str1! | strrpc "<location>" "" | strrpc "</location>" "">> result.txt)
)
set num=0
)
rem 处理result.txt引号
for /f "tokens=2 delims=>" %%z in ('type result.txt') do (
for /f "delims=<" %%z in ("%%z")do echo %%z >> last.txt
)
rem 将last.txt命名为last.csv
rename last.txt last.csv

pause

https://www.uoften.com/serverhost/winhost/20180415/80863.html
页: [1]
查看完整版本: windows下Nginx日志处理脚本