我是一名批处理文件新手。 请问是否能帮我编写一个批处理脚本,用于解析以下格式的csv文件:
"Expert Info (Chat/Sequence): GET /?password=Katy HTTP/1.1\r\n","Feb 20, 2014 19:34:46.571807000","b5:54:f4:v7:xo:6l"
"Expert Info (Chat/Sequence): GET /?password=Cory HTTP/1.1\r\n","Feb 20, 2014 19:34:51.671167000","b5:54:f4:v7:xo:6l"
"Expert Info (Chat/Sequence): GET /?password=Mike HTTP/1.1\r\n","Feb 20, 2014 19:34:57.145898000","b5:54:f4:v7:xo:6l"
并将其转换为另一个看起来像这样的csv文件:
"Katy", "2014-02-20", "19:34:46", "b5:54:f4:v7:xo:6l"
"Cory", "2014-02-20", "19:34:51", "b5:54:f4:v7:xo:6l"
"Mike", "2014-02-20", "19:34:57", "b5:54:f4:v7:xo:6l"
以下是我写的内容:
@echo off
FOR /F "tokens=6,8,9,10,11* delims=,? " %%a in (file.csv) do (
set pass=%%a
set month=%%b
set day=%%c
set year=%%d
set sec=%%e
set mac=%%f
echo "%%a" %%b %%c %%d %%e %%f
if %month:~1,10%==Jan set month=01
if %month:~1,10%==Feb set month=02
if %month:~1,10%==Mar set month=03
if %month:~1,10%==Apr set month=04
if %month:~1,10%==May set month=05
if %month:~1,10%==Jun set month=06
if %month:~1,10%==Jul set month=07
if %month:~1,10%==Aug set month=08
if %month:~1,10%==Sep set month=09
if %month:~1,10%==Oct set month=10
if %month:~1,10%==Nov set month=11
if %month:~1,10%==Dec set month=12
echo "%pass:~9,4%", "%year%-%month:~1,10%-%day%", "%sec:~,8%", %mac% >> text.csv)
for
命令 - 特别是使用/f
开关。你应该在这里发布你遇到的问题,而不是问题本身。 - unclemeat