中国DOS联盟论坛

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-08-02 02:26
48,037 topics / 350,122 posts / today 2 new / 48,250 members
DOS批处理 & 脚本技术(批处理室) » [Discussion]Data Query and Database Operation Scripts
Printable Version  1,458 / 10
Floor1 maya0su Posted 2006-08-15 23:09
中级用户 Posts 131 Credits 241
Today I went to a company. During the waiting process, suddenly a phone call asked the clerk for someone's phone number. I saw that clerk drag the scroll bar with the mouse to find that name one by one and then report the phone number!

Suddenly I felt it was very funny, and I thought if there was a batch script that could solve this problem?

On the bus on the way back, I kept thinking about this problem... But after I solved this problem, I felt that the根本 existence meaning of this batch script was gone, because whether it was Word or Excel or even Notepad, there were all functions to find strings... Hey...

But since I wrote it, I'll post the code... for everyone to have a laugh... Hehe...

@echo off
set /p uu=Please enter the name or phone number you want to find:
type config.cfg |find /i "%uu%"
echo.
echo.
echo.
pause
exit

Description: config.cfg is the configuration file of CS. I estimate everyone knows this, and those three echo. are to have a blank space after finding and displaying, so that the display of pause does not affect the normal display output, making it easier to view!

[ Last edited by willsort on 2006-8-22 at 03:21 ]
Floor2 mornsmile Posted 2006-08-16 07:28
初级用户 Posts 23 Credits 147
You mentioned CS, does it refer to Counter-Strike? Then what's the relation to the phone?
Floor3 xjmxjm1234 Posted 2006-08-16 13:11
中级用户 Posts 166 Credits 361
Is `cs` a register?


So that the display of `pause` does not affect the normal display output, making it easier to watch!

Isn't it enough to use `pause > nul`?


But since it's written out, just post the code... for everyone to have a laugh... heh heh...

It doesn't matter. The most important thing about batch commands is not being proficient, but innovation.
Floor4 无奈何 Posted 2006-08-16 22:19
荣誉版主 Posts 356 Credits 1,338
I think the purpose of writing a script is to conveniently solve some practical problems. As long as script writing is needed, it must meet specific requirements. The other consideration is just to see if it is practical.
There was a period when I needed to frequently check the postal codes and area codes of some places, so I made the following script. In order to format the output and enhance the fault tolerance of input, gawk.exe was used. Since it was not made very carefully, I was not very satisfied and did not show it off.
The usage method is: for example, to check the postal code of my hometown Tai'an, it can be like this
1、YBQH 泰安
2、YBQH tai an
3、YBQH taian
4、YBQH ta
5、YBQH 0538
It can also run with empty parameters and input according to the prompt. Among them, returning many non-desired results according to the initials of pinyin. Other files are in the attachment. Since I can't upload the attachment today, there seems to be a problem with the upload system. Let me know if you need it.
YBQH.bat


  1. ::Simple postal code and area code query program
  2. ::BY 无奈何@cn-dos.net
  3. @echo off
  4. title Postal code and area code query
  5. echo.
  6. gawk -f find.awk %*
  7. goto next

  8. :loop
  9. echo.
  10. gawk -f find.awk
  11. :next
  12. echo.
  13. set j=
  14. set /p j= Press "0" key or space bar to continue; any other key to exit....
  15. if "%j%" == " " goto loop
  16. if "%j%" == "0" (goto loop) else exit
  17. goto :end
  18. :end
Written by 无奈何 on 2006-08-16 21:51


find.awk
Floor5 hanbsome Posted 2006-08-16 22:43
初级用户 Posts 14 Credits 36
Wow, you've even come up with such a batch script. I'm impressed.
Floor6 maya0su Posted 2006-08-16 22:52
中级用户 Posts 131 Credits 241
CS is the configuration file for Counter-Strike, but here I'm using it as a substitute for a phone book!
I have a bad habit, which is always posting the actual files instead of the files I actually envisioned.
After reading the code of the helpless version master, I think my code still needs to be improved a bit.
In fact, it doesn't matter whether the code is useful or not. The most important thing is that we need to think about whether we can make the computer make life simpler...
Floor7 3742668 Posted 2006-08-17 20:44
荣誉版主 Posts 718 Credits 2,013
But after I solved this problem, I felt that this batch processing doesn't have any meaning at all, because both Word and Excel, and even Notepad, have the function of finding strings... Hey...

You don't need to be too self-deprecating. Not to mention whether it's useful or not, every time you write a script, your ability to write scripts will improve. Simply the flexibility and diversity of scripts are incomparable to popularized programs. Of course, without popularized applications, the functions of scripts will also be greatly affected. In fact, my main point is: Don't put scripts and applications on opposite sides, but should consider how to make scripts combine with applications to play their roles more greatly.
For example, the following is something pieced together from a few of my previous scripts:
BAT file part:

Note: There is a carriage return at the end of the code, and the file name can be arbitrary.

VBS file part:

Note: The saved file name must be: 数据库脚本.vbs
Originally planned to echo the vbs file in the bat, but because the code is too long, it is separated into two files. Since the code is pieced together from a few of my previous scripts, there are inevitable deficiencies, and everyone can modify it by themselves for fun.

Attachments
脚本.rar (2.05 KiB)
Floor8 zrz000 Posted 2006-08-18 18:39
初级用户 Posts 16 Credits 44
I've learned a lot again.. I need to come up more often in the future///
Floor9 maya0su Posted 2006-08-20 11:17
中级用户 Posts 131 Credits 241
### 1. What does `more +52 %1` mean?
`more` is a command in DOS (Disk Operating System) used to view the content of a file. The `+52` option means to start displaying the file starting from the 52nd line. `%1` is a batch file parameter, which represents the first command-line argument passed to the batch script. So `more +52 %1` means to use the `more` command to display the file passed as the first argument starting from the 52nd line.

### 2. Why use two pipe symbols for `|| echo 记录不存在!`?
In batch scripting, the `||` operator is a logical OR operator. It means that if the preceding command (in this case, `findstr %str%`) returns a non-zero exit code (indicating that the search did not find a match), then the command following `||` (here, `echo 记录不存在!`) will be executed. So `findstr %str% || echo 记录不存在!` means: if `findstr %str%` does not find the string `%str%`, then output "记录不存在!" (which means "Record does not exist!"). The two pipe symbols are used to connect the `findstr %str%` command and the `echo 记录不存在!` command in the logical OR structure.
Floor10 namejm Posted 2006-08-20 13:32
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Originally posted by maya0su at 2006-8-20 11:17:
Please ask the following
more +52 %1 | findstr %str% || echo Record not found!
1. What does more +52 %1 mean?
2. Why use two pipe symbols for || echo Record not found!?
Please explain...


  1. Display the content of the file starting from line 52;

  2. || is not the use of two consecutive pipe symbols, but it means that if the previous statement fails to execute, then the subsequent statement is executed; similarly, && means that the subsequent statement is executed only after the previous statement is executed successfully;

[ Last edited by namejm on 2007-2-5 at 10:41 AM ]
Floor11 maya0su Posted 2006-09-04 08:36
中级用户 Posts 131 Credits 241
To add a "delete" option to this batch script, you can modify it as follows:

```batch
@echo off
title 电话本查找工具
color 0A
:start
cls
echo.
echo.
echo 查找电话或姓名----1
echo 添加电话或姓名----2
echo 删除电话或姓名----3
echo 退出本程序--------4
echo.
echo.
set /p var=选择:
set var=%var:~0,1%
call :%var% %0 2>nul || goto :eof


:1
cls
set /p uu=请输入你要查找的姓名或电话号码:
type 电话本.txt | find /i "%uu%" || echo 没有找到你要查找的姓名和电话
echo.
echo.
echo.
pause
goto :start

:2
cls
set /p nn=请输入你要添加的姓名和电话:
echo %nn% >>电话本.txt
echo 添加完毕.
echo.
echo.
echo.
pause
goto :start

:3
cls
set /p del_str=请输入要删除的姓名或电话号码:
findstr /v /c:"%del_str%" 电话本.txt > temp.txt
move /y temp.txt 电话本.txt >nul
echo 删除完毕.
pause
goto :start

:4
exit
```

Here's the explanation of the added part:

- Added a new option "3" for deleting.
- In the `:3` label, it uses `findstr /v` to find lines that do not match the string to be deleted, saves the result to a temporary file, and then moves the temporary file back to replace the original phone book file to achieve the deletion function.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023