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-07-02 08:26
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Puzzles and Solutions: Application of find in Batch Processing View 5,680 Replies 13
Original Poster Posted 2004-11-18 00:00 ·  中国 山西 运城 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
To All:
Application platform: Windows 9x / Windows NT's / MS-DOS 6.xx
Problem description: There are two find statements in the batch program test.bat, namely find_A and find_B. Their functions are: find_A can filter the line where find_B is located into the program test1.bat, and find_B can filter all lines except the line where find_A is located into the program test2.bat. How to write find_A and find_B?
Additional instructions: The program should be runnable on the above-mentioned three platforms. If not, it can be a second choice; the content of other statements in the program cannot be determined. It can contain any possible strings that may appear in find_A and find_B. If not, it can be a second choice; there is no additional reward for this solicitation, just to broaden everyone's programming ideas.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
8417a +1 2010-01-07 15:43
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 2 Posted 2004-11-19 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
I can't understand your intention. I don't know whether the so-called find_A and find_B are just code names for these two Find statements or represent a specific command (such as two batch files using the Find statement). Since we need to distinguish between two different Finds, it can be affirmed that there must be distinguishable marks between these two finds. The batch files written by experts are hard to understand, and even the problems raised are hard to understand. Oh, my god...
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2004-12-04 00:00 ·  中国 山西 运城 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re Climbing: find_a and find_b are just code names for statements, and the actual implementation still uses the external command find. There must be distinguishable flags, but this flag has some particularity. Because the flag of find_b cannot appear in find_a, otherwise the separate filtering of find_b cannot be realized, but find_a itself requires distinguishable find_a flags, so a contradiction is encountered. For example, in the following situation, find_b: is the same as in the current find_a and find_b, and the separate filtering of find_a and find_b cannot be done. Summary: The find statement filters/anti-filters a certain statement in its own batch file, but cannot filter/anti-filter itself. How to implement it? find_a: find "find_b:" <...>... find_b: find "find_a:" /v <...>....
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 4 Posted 2004-12-04 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
racked my brains, and I found that these two statements form a paradox. No matter what, I can't find a unique identifier to mark myself. If the find command supports regular expressions, then the problem would be easily solved. I know there must be a solution, but I'm too stupid. Therefore, please brother willsort to publish the answer. In Windows 2000/xp/2003 (supporting the findstr command), you can use this batch script:
@echo off
set src=
if exist %0.cmd set src=%0.cmd
if %src%#==# if exist %0.bat set src=%0.bat
if %src%#==# set src=%0
TYPE %src% | findstr "^type" > test1.bat
type %src% | findstr "^TYPE" > test2.bat
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 5 Posted 2004-12-06 00:00 ·  中国 山西 运城 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
关于Climbing:等了许久,只有Climbing兄一人作答,看来此题实在不适合作为争鸣类的题目。之所以将此题提出来讨论,是因为确实曾经有人实现过,但已经随着我的前期资料一起遗失了。而我现在的答案也不很完善,所以希望有人可以查缺补遗。下面是我的解答,它的缺憾之处,在于无法保证它的关键字在其它语句中不会出现。
@echo off
if exist %0 set me=%0
if exist %0.bat set me=%0.bat
echo find a in %me%
find " < %%me%% > test2.bat" < %me% > test1.bat
echo find b in %me%
find " < %%me%% > test1.bat" /v < %me% > test2.bat
set me=
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 6 Posted 2004-12-06 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
There are some issues with Brother willsort's program. Modify as follows:

@echo off
if exist %0 set me=%0
if exist %0.bat set me=%0.bat
echo find a in %me%
find " < %%me%% > test2.bat" < %me% > test1.bat
echo find b in %me%
:: The following line should not have /v.
find " < %%me%% > test1.bat" < %me% > test2.bat
set me=
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 7 Posted 2004-12-06 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
It is indeed very cleverly implemented. The key lies in the use and reference of the %me% environment variable, which leads to completely different marks in the two find statements. High, really high!
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 8 Posted 2004-12-06 00:00 ·  中国 山西 运城 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re Climbing: “/v” is the anti-filter parameter, which is necessary because "find_B can filter all lines except the line where find_A is located into the program test2.bat"
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 9 Posted 2004-12-06 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Sorry, I didn't see the original question clearly. I thought it was that Find_a filters the lines where Find_b is located, and Find_b filters the lines where Find_a is located.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 10 Posted 2005-12-24 13:06 ·  中国 广东 东莞 联通
新手上路
Credits 4
Posts 2
Joined 2005-12-24 11:03
20-year member
UID 47770
Status Offline
Oh, you two can play here slowly. I'm leaving, I'm leaving
Floor 11 Posted 2005-12-24 17:59 ·  中国 广东 广州 白云区 电信
荣誉版主
★★★
Credits 718
Posts 313
Joined 2005-09-26 00:00
20-year member
UID 42844
Gender Male
Status Offline
Don't post if you just pass by.

But thank you for bumping this classic post.

Support this kind of problem-solving post! But don't make it too difficult to discourage people.
Floor 12 Posted 2006-06-28 07:56 ·  中国 安徽 芜湖 电信
高级用户
★★★
Credits 866
Posts 415
Joined 2005-12-04 11:19
20-year member
UID 46459
Status Offline
To be honest, even when programming in C++, programmers would add annotations. But I've noticed that the high - difficulty and high - skill batch scripts written by the experts in this DOS forum never have any annotations. It makes rookies like me completely confused. I might spend half an hour on a single line of batch script and still not understand it. Wouldn't it be much more efficient if there were annotations at the end?

Maybe we rookies are too green, which makes you laugh. But I still have to say it. Because isn't this forum supposed to support newbies? ;):o

[ Last edited by htysm on 2006 - 6 - 28 at 08:00 ]
Floor 13 Posted 2006-06-28 13:05 ·  中国 广东 珠海 电信
初级用户
Credits 112
Posts 40
Joined 2006-06-23 19:52
20-year member
UID 57473
Gender Male
Status Offline
Well, that makes sense. I originally thought that DOS batch processing couldn't achieve many functions. I didn't expect that after coming to this DOS Union, I realized that the experts are so brilliant! The things they wrote I know are very classic and I envy them. But unfortunately, I can't understand them very well. Haha. I estimate I need to study for another half a year to understand half of what they wrote.

Even so, coming here has made me have a new understanding of batch processing and I think it has a bright future. Since I'm a software tester, I don't have time to do specialized development like Java, and I'm content with just writing some simple batch processing programs. Live happily.

Our company stipulates that more than 90% of the code should be commented, haha.
Floor 14 Posted 2009-08-30 04:38 ·  中国 广东 广州 荔湾区 电信
新手上路
Credits 5
Posts 3
Joined 2009-08-23 16:26
16-year member
UID 150845
Gender Male
Status Offline
Originally posted by htysm at 2006-6-28 07:56:
To be honest, even when programming in C++, programmers would mark explanations. But I saw that the high-level batch scripts written by the experts in this DOS forum never have any explanations, making us noobs confused...

Indeed!
I really hope that in the future, when experts write some high-level batch scripts, they will include comments! Then we noobs can also know how that command is used. Otherwise, after reading it, we still don't understand, and our level can't improve!
Forum Jump: