![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-29 18:56 |
47,813 topics / 349,918 posts / today 0 new / 48,278 members |
| DOS批处理 & 脚本技术(批处理室) » Puzzles and Solutions: Application of find in Batch Processing |
| Printable Version 5,934 / 13 |
| Floor1 willsort | Posted 2004-11-18 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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. |
|
| Floor2 Climbing | Posted 2004-11-19 00:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
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...
|
|
| Floor3 willsort | Posted 2004-12-04 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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 <...>....
|
|
| Floor4 Climbing | Posted 2004-12-04 00:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
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 |
|
| Floor5 willsort | Posted 2004-12-06 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
关于Climbing:等了许久,只有Climbing兄一人作答,看来此题实在不适合作为争鸣类的题目。之所以将此题提出来讨论,是因为确实曾经有人实现过,但已经随着我的前期资料一起遗失了。而我现在的答案也不很完善,所以希望有人可以查缺补遗。下面是我的解答,它的缺憾之处,在于无法保证它的关键字在其它语句中不会出现。
@echo off |
|
| Floor6 Climbing | Posted 2004-12-06 00:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
There are some issues with Brother willsort's program. Modify as follows:
|
|
| Floor7 Climbing | Posted 2004-12-06 00:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
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!
|
|
| Floor8 willsort | Posted 2004-12-06 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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"
|
|
| Floor9 Climbing | Posted 2004-12-06 00:00 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
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.
|
|
| Floor10 nsdos | Posted 2005-12-24 13:06 |
| 新手上路 Posts 2 Credits 4 | |
|
Oh, you two can play here slowly. I'm leaving, I'm leaving
|
|
| Floor11 220110 | Posted 2005-12-24 17:59 |
| 荣誉版主 Posts 313 Credits 718 | |
|
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. |
|
| Floor12 htysm | Posted 2006-06-28 07:56 |
| 高级用户 Posts 415 Credits 866 | |
|
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 ] |
|
| Floor13 zhaxi | Posted 2006-06-28 13:05 |
| 初级用户 Posts 40 Credits 112 | |
|
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. |
|
| Floor14 net72 | Posted 2009-08-30 04:38 |
| 新手上路 Posts 3 Credits 5 | |
Originally posted by htysm at 2006-6-28 07:56: 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! |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |