|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『楼 主』:
疑难征解:批处理中的find应用
使用 LLM 解释/回答一下
To All:
应用平台:Windows 9x / Windows NT's / MS-DOS 6.xx
问题描述:批处理程序 test.bat 中有两个find语句,分别是find_A与find_B。他们的作用为:find_A 可以将find_B所在的行过滤至程序test1.bat中,find_B 可以将find_A所在行之外的所有行过滤至程序test2.bat中。请问find_A和find_B如何编写?
附加说明:程序应该可以在以上提到的三种平台下均可运行,如果无法可以求其次;程序中其他语句无法确定其内容,它可含有任何可能出现在find_A和find_B中的字符串,如果无法可以求其次;本次征解无任何额外奖励,只是借此开阔一下大家的编程思路而已。
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.
此帖被 +1 点积分 点击查看详情 评分人:【 8417a 】 | 分数: +1 | 时间:2010-1-7 15:43 |
|
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2004-11-18 00:00 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
看不明白你的意图,不知道你所谓的find_A和find_B只是这两条Find语句的代号,还是代表一个具体的命令(例如使用Find语句的两个批处理),既然要区分出两条不同的Find,那可以肯定的就是这两个find之间必定有可供区分的标志。高手写的批处理让人看不懂,连出的问题也让人看不懂,晕ing...
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...
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2004-11-19 00:00 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
Re Climbing: find_a 和 find_b 都只是语句的代号,真正的实现仍然使用外部命令find。至于可供区分的标志肯定应该有,只是这个标志有些特殊性。因为find_b的标志不能出现在find_a中,否则就无法实现对find_b的单独过滤,但是find_a本身又要求可供识别的find_a标志,所以遇到了矛盾。比如下面的情况,find_b:便同现在find_a与find_b中,无法单独过滤其中的find_a和find_b。 总结:find语句过滤/反过滤自身所在批处理中的某一条语句,但不能过滤/反过滤自身,如何来实现? find_a: find "find_b:" <...>... find_b: find "find_a:" /v <...>....
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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2004-12-4 00:00 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
想破脑袋,发现这两条语句是一个悖论,无论如何我也找不到一个唯一标识自己的标志,如果find命令支持正则表达式,那么问题就很容易解决。我知道肯定是有解决方法的,但我太愚笨了。因此,请willsort兄公布答案。在Windows 2000/xp/2003(支持findstr命令)下可以用这个批处理:
@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
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
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2004-12-4 00:00 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Re 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=
关于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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2004-12-6 00:00 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
willsort兄的程序有些问题,修改如下:
@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%
:: 下面一行应该没有/v的。
find " < %%me%% > test1.bat" < %me% > test2.bat
set me=
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=
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2004-12-6 00:00 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
实现的确实很巧妙,关键处就在于%me%环境变量的使用及引用,导致两个find语句出现完全不同的标志,高,实在是高!
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!
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2004-12-6 00:00 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Re Climbing: “/v” 是反过滤参数,是必要的,因为“find_B 可以将find_A所在行之外的所有行过滤至程序test2.bat中“
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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2004-12-6 00:00 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
Sorry,我没有看清原题意,我还以为是Find_a过滤Find_b所在的行,而Find_b则过滤Find_a所在的行呢。
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.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2004-12-6 00:00 |
|
|
nsdos
新手上路

积分 4
发帖 2
注册 2005-12-24
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
我倒。。。
你们俩在这里慢慢玩吧,
我闪,我闪
Oh, you two can play here slowly. I'm leaving, I'm leaving
|
|
2005-12-24 13:06 |
|
|
220110
荣誉版主
      
积分 718
发帖 313
注册 2005-9-26
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
路过就不要发贴了嘛。
不过也谢谢你顶起这经典的贴。
支持这种求解贴!但不要太过难了,让人望而却步。
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.
|
|
2005-12-24 17:59 |
|
|
htysm
高级用户
   
积分 866
发帖 415
注册 2005-12-4
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
说实话,就是用C++编程,程序员也会标注说明的,可我看到这个DOS论坛里的高手写出的高难度高技巧的批处理从来就没有说明,让我等菜鸟看得云头雾里,一行批处理我要看半个钟头还不知所以然.如果在后边标注个说明岂不事半功倍.
可能是我等菜鸟太菜,让你们见笑了.但是我还要说.因为你这个论坛不就是要扶持新人吗?;):o
Last edited by htysm on 2006-6-28 at 08:00 ]
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 ]
|
|
2006-6-28 07:56 |
|
|
zhaxi
初级用户
 
积分 112
发帖 40
注册 2006-6-23
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
恩,有道理。我本来以为dos批处理实现不了什么功能的。没有想到来了这个dos联盟,才知道高手竟然是那样的高! 他们写的东西我知道很经典,也很羡慕。可惜就是看不太懂。哈哈。估计我要再学半年才能看懂他们写的一半吧。
尽管如此,来了这里我还是重新有了对批处理的认识,觉得很有前途。由于我是软件测试人员,所以我没有时间去搞专门的java等开发,自己只要编些简单的批处理程序就很知足了。生活过的开心。
我们公司规定对90%以上的代码要作注释,哈哈。
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.
|
|
2006-6-28 13:05 |
|
|
net72
新手上路

积分 5
发帖 3
注册 2009-8-23
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
Originally posted by htysm at 2006-6-28 07:56:
说实话,就是用C++编程,程序员也会标注说明的,可我看到这个DOS论坛里的高手写出的高难度高技巧的批处理从来就没有说明,让我等菜鸟看得云头雾里,一 ...
确实啊
以后真的希望高手们能在写一些高难度的批处理的时候写上注释!我们菜鸟看了也知道那个命令究竟怎么用,不然看了还是没有理解,水平还是无法提高!
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!
|
|
2009-8-30 04:38 |
|