@echo off rem 保存为bat文件跟txt文件放一起运行 md "结果\" 2>nul for /f "delims=" %%a in ('dir /a-d/b *.txt') do ( setlocal EnableDelayedExpansion (for /f "delims=" %%b in ('type "%%a"') do ( set "str=%%b" echo;!str: =,! ))>"结果\%%~na.csv" Endlocal ) pause
@echo off set str=100x200x300y400y500x600y700 for /f "tokens=1,3-5,* delims=x|y" %%a in ("%str%") do ( set c1=%%a set c3=%%b set c4=%%c set c5=%%d set c6=%%e ) echo %c1%, %c3%, %c4%, %c5%, %c6% pause rem 输出结果为输出结果为:100, 300, 400, 500, 600y700。其中tokens=1,3-5,*表示提取第1、3至5列,同时把第5列后所有剩余字符串作为第6列,一个输出了5个变量,也可以写作tokens=1,3,4,5,*。
@echo off md "结果\" 2>nul rem 循环数据 for /f "delims=" %%a in ('dir /a-d/b *.log') do ( setlocal EnableDelayedExpansion rem 切割方式 (for /f "tokens=1,2 delims=_| " %%b in ('type "%%a"') do ( set "str1=%%b %%c" echo;!str1: =,! ))>"结果\%%~na.csv" Endlocal ) pause