China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-15 13:10
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » 请问如何删除特定行的文件? Translated: How to delete files with specific lines? View 1,953 Replies 5
Original Poster Posted 2010-12-21 16:12 ·  中国 上海 电信
新手上路
Credits 8
Posts 3
Joined 2010-06-15 20:46
16-year member
UID 168895
Gender Male
Status Offline
Check the specified folder. If a line in a TXT file inside it is "HHHHHHH", immediately delete that file. If "HHHHHHH" appears in other lines, it can be ignored. The following code doesn't seem to solve my problem. Who is willing to help take a look? Thanks

set old=d:\test
set SRT1=HHHHHHH

for /f "delims=" %%c in ('dir /b /s /a-d "%old%\*.txt"') do (
for /f "delims=" %%d in (%%c) do (
if *%%d*==*%STR1%* del %%c))
Floor 2 Posted 2010-12-22 16:16 ·  中国 上海 电信
新手上路
Credits 8
Posts 3
Joined 2010-06-15 20:46
16-year member
UID 168895
Gender Male
Status Offline
Is there anyone to help take a look? Thanks.
Floor 3 Posted 2010-12-22 17:22 ·  中国 上海 电信
新手上路
Credits 8
Posts 3
Joined 2010-06-15 20:46
16-year member
UID 168895
Gender Male
Status Offline
Is my question is too simple or not explained clearly?

Suppose there are many TXT files in a directory:

File A:
123
456
123456


File B:
123
888
88456

If a specific string 456 is given, then file A should be deleted because the second line is exactly 456. And file B does not need to be deleted because 456 is only part of its third line.

Can anyone help? Or give a hint, I'm very new to this...
Floor 4 Posted 2010-12-24 00:04 ·  中国 上海 杨浦区 电信
管理员
★★
Credits 389
Posts 198
Joined 2008-09-23 12:00
17-year member
UID 126405
Gender Male
Status Offline
Check if you posted in the wrong place:
http://www.cn-dos.net/forum/viewthread.php?tid=46409
Floor 5 Posted 2010-12-26 16:14 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
If you are using the DOS system, its for command does not support /f.
Floor 6 Posted 2010-12-26 21:55 ·  中国 上海 杨浦区 电信
金牌会员
★★★★
Credits 4,639
Posts 2,239
Joined 2005-01-30 00:00
21-year member
UID 35785
Gender Male
Status Offline
To be precise, it's that the FOR command in COMMAND that comes with DOS doesn't support the /f parameter. But if you use 4DOS as the command interpreter, it does support it.
Forum Jump: