- 帖子
- 70
- 积分
- 107
- 技术
- 3
- 捐助
- 0
- 注册时间
- 2018-11-17
|
[文本处理] [已解决]请教如何使用批处理把文本a.txt里数组过滤后输出到b.txt
本帖最后由 wxyz0001 于 2019-10-25 21:10 编辑
请教如何使用批处理把文本a.txt里数组过滤后输出到b.txt
问题如下:
a.txt里的数据如下:
02,03,12,31,33
02,03,15,26,35
02,03,19,23,34
02,03,16,24,33
02,04,19,26,30
02,03,20,23,33
02,04,20,25,31
02,06,21,24,32
02,07,08,31,33
02,08,20,25,26
03,08,19,20,31
03,08,19,25,26
03,08,22,24,25
过滤条件如下:
a.txt里有3个偶数以上的一组输出到b.txt里
输出结果为
02,03,16,24,33
02,04,19,26,30
02,04,20,25,31
02,06,21,24,32
02,08,20,25,26
03,08,22,24,25
谢谢bat-flashercs
===========================================
@echo off
setlocal EnableDelayedExpansion
set "file1=a.txt"
set "file2=b.txt"
cd /d "%~dp0"
(
for /f "usebackq delims=" %%A in ("%file1%") do (
set ctr=0
for %%B in (%%~A) do (
set /a "t=1%%B&1"
if !t! equ 0 set /a "ctr+=1"
)
if !ctr! geq 3 echo %%A
)
)>"%file2%"
endlocal
pause
exit /b
===========================================
我作了下修改,这样比较容易理解
@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%a in (a.txt) do (
set ctr=0
for %%b in (%%a) do (
set /a "t=1%%b&1"
if !t! equ 0 set /a ctr+=1
)
if !ctr! geq 3 echo %%a>>b.txt
)
pause
=========================================== |
|