1st option
If you only need files that contain lines like:
1 ^ 2 ^ 65350 ^ text ^ text ^ 15.2046 ^ 7 ^ 0 ^ 6 ^ 2 ^^ 201 ^ 132 ^ 2004 ^ SC ^ MS ^^
but not
1 ^ 123 ^ 65350 ^ text ^ text ^ 15.2046 ^ 7 ^ 0 ^ 6 ^ 2 ^^ 201 ^ 132 ^ 2004 ^ SC ^ MS ^^
(save code as .cmd):
@echo off setlocal enabledelayedexpansion :: Π·Π΄Π΅ΡΡ ΡΠΊΠ°ΠΆΠΈΡΠ΅ ΠΏΡΡΡ ΠΊ ΡΠ°ΠΉΠ»Π°ΠΌ ΠΈ ΠΌΠ°ΡΠΊΡ Π΄Π»Ρ ΠΏΠΎΠΈΡΠΊΠ° set files=D:\3\*.txt for %%f in (%files%) do ( set found= for /f "skip=1 tokens=2 delims=^^" %%l in (%%f) do if "%%l" equ "2" set found=1 if "!found!" equ "" echo del /q %%f )
2nd option
If you also need files in which there are lines like:
1 ^ 123 ^ 65350 ^ text ^ text ^ 15.2046 ^ 7 ^ 0 ^ 6 ^ 2 ^^ 201 ^ 132 ^ 2004 ^ SC ^ MS ^^
those. after the first character ^ there is any number containing a two, then:
@echo off setlocal enabledelayedexpansion :: Π·Π΄Π΅ΡΡ ΡΠΊΠ°ΠΆΠΈΡΠ΅ ΠΏΡΡΡ ΠΊ ΡΠ°ΠΉΠ»Π°ΠΌ ΠΈ ΠΌΠ°ΡΠΊΡ Π΄Π»Ρ ΠΏΠΎΠΈΡΠΊΠ° set files=D:\3\*.txt for %%f in (%files%) do ( set found= for /f "skip=1 tokens=2 delims=^^" %%l in (%%f) do ( echo %%l | find "2" > nul if "!errorlevel!" equ "0" set found=1 ) if "!found!" equ "" echo del /q %%f )
PS: If everything works as it should, do not forget to delete echo before del for real deletion of files.
By the way, if the files are large, then you can use such a script - it should work faster (only for the first option):
@echo off :: Π·Π΄Π΅ΡΡ ΡΠΊΠ°ΠΆΠΈΡΠ΅ ΠΏΡΡΡ ΠΊ ΡΠ°ΠΉΠ»Π°ΠΌ ΠΈ ΠΌΠ°ΡΠΊΡ Π΄Π»Ρ ΠΏΠΎΠΈΡΠΊΠ° set files=D:\3\*.txt for %%f in (%files%) do call :check %%f goto :eof :check for /f "skip=1 tokens=2 delims=^^" %%l in (%1) do if "%%l" equ "2" goto :eof echo del /q %1