我有一个包含18个字段的批处理文件。字段8是整数(1、2、3等)。我想删除字段8 = 13的任何行。下面的代码未返回整行;它返回值!line!而不是csv文件中的实际行。如何更新此代码以删除字段8等于13的任何行?
line1
line2
line3
line4
1,MAY090178,D ,BATMAN HUSH COMPLETE TP,24.99,11.2455,11.25,13,7, ,62464962,7.61941E+16,1401223176,9.7814E+17, ,0,DC COMICS,0
1,NOV141747,F ,BLACK BUTLER GN VOL 19,13,7.54,7.54,13,7, ,62464962,,316259403,9.78032E+17, ,0,YEN PRESS,127143
2,MAY151682,F ,BLACK BUTLER GN VOL 20,13,7.54,15.08,13,7, ,62464962,,316305014,9.78032E+17, ,0,YEN PRESS,127143
1,AUG180208,D ,BULLY WARS #2 CVR A CONLEY,3.99,1.7955,1.8,13,7, ,62464962,7.09853E+16,,, ,0,IMAGE COMICS,140749
1,OCT180162,D ,BULLY WARS #4 CVR A CONLEY,3.99,1.7955,1.8,13,7, ,62464962,7.09853E+16,,, ,0,IMAGE COMICS,140749
10,SUPPLY123,J ,COMICARE LONG COMIC BOX (SOLD IN 10) (NET),2.53,2.533,25.33,12,7, ,62464962,6.0326E+11,,, ,0,,0
2,SEP180823,D ,FANTASTIC FOUR #4,3.99,1.8753,3.75,1,7, ,62464962,7.59606E+16,,, ,0,MARVEL COMICS,140538
1,JUN160567,E ,FROM HELL HC,39.99,19.995,20,3,7, ,62464962,,1603093974,9.7816E+17, ,0,IDW - TOP SHELF,0
2,APR162146,F ,FRUITS BASKET COLLECTORS ED TP VOL 01,20,11.6,23.2,3,7, ,62464962,,316360163,9.78032E+17, ,0,YEN PRESS,136243
1,JUL110352,E ,GODZILLA KINGDOM OF MONSTERS TP VOL 01,17.99,8.995,9,3,7, ,62464962,,1613770162,9.78161E+17, ,0,IDW PUBLISHING,129254
@echo off & Setlocal EnableDelayedExpansion
rem | Remove category 13 lines
rem SET "sourcedir=d:\data"
rem SET "destdir=d:\data"
rem SET "filename=%sourcedir%\file.csv"
rem SET "outfile=%destdir%\outputfile.csv"
Setlocal EnableDelayedExpansion
for /f "tokens=1,* delims=," %%A in (file.csv) do (
SET line=%%A
SET string=%%H
if NOT "string"=="13" >> file_13.csv echo(!line!
endlocal
)
@echo on
答案 0 :(得分:4)
clockz
告诉解析器将字符串拆分为逗号,将第一个标记放入"tokens=1,* delims=," %%A
中,然后将其他所有内容放入%%A
中。如果需要更多变量,则必须指定期望的令牌数。另外,一旦拆分了字符串,就无法访问未拆分的字符串,因此必须手动重建它。
%%B