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-06-28 06:01
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Batch processing problem, humbly asking experts for advice?[Help] View 2,408 Replies 13
Original Poster Posted 2003-10-01 00:00 ·  中国 湖北 荆门 京山市 电信
初级用户
Credits 183
Posts 15
Joined 2003-07-07 00:00
22-year member
UID 6493
Gender Male
Status Offline
I want to use batch processing to complete the following functions, please help

a. Find the specified string "LIZI" in the text. If found, assign the text after the space to %1, %2, %3, %4, %5, %6, %7, %8, %9... until the carriage return character is detected, and exit.
If not found, add a line in this text. The content is a string starting with "LIZI" and add the default values of %1, %2, %3, %4, %5, %6, %7, %8, %9... which is the value of the first line
For example, in AAA.TXT there is
name date1 date2 date3
lizi 001 002 003
Looking for lizi in AAA.TXT, there is %1=001, %2=002, %3=003
Looking for name4 in AAA.TXT, AAA.TXT has no change to
name date1 date2 date3
lizi 001 002 003
name4 date1 date2 date3

b. Perform mathematical operations in batch processing and assign values to variables




Floor 2 Posted 2003-10-02 00:00 ·  中国 湖北 荆门 京山市 电信
初级用户
Credits 183
Posts 15
Joined 2003-07-07 00:00
22-year member
UID 6493
Gender Male
Status Offline
Does nobody know?
Floor 3 Posted 2003-10-02 00:00 ·  中国 湖北 武汉 联通
银牌会员
★★★
Credits 1,681
Posts 512
Joined 2003-08-02 00:00
22-year member
UID 7953
Gender Male
Status Offline
It seems that debug needs to be used, and the easiest way is to use QB/C
Somehow somewhere I've got to choose.
No matter if it is win or lose.
Floor 4 Posted 2003-10-02 00:00 ·  中国 湖北 荆门 京山市 电信
初级用户
Credits 183
Posts 15
Joined 2003-07-07 00:00
22-year member
UID 6493
Gender Male
Status Offline
I don't know if the enhanced script tool will work.

If batch processing is not possible,

please ask the expert to help write a program to complete
Floor 5 Posted 2003-10-04 00:00 ·  中国 湖北 荆门 京山市 电信
初级用户
Credits 183
Posts 15
Joined 2003-07-07 00:00
22-year member
UID 6493
Gender Male
Status Offline
Where are the experts? Come out and help!, this will be very useful when done
Floor 6 Posted 2003-10-04 00:00 ·  中国 湖北 武汉 联通
银牌会员
★★★
Credits 1,681
Posts 512
Joined 2003-08-02 00:00
22-year member
UID 7953
Gender Male
Status Offline
First, let's talk about your idea. Maybe we can try another way to do it.
Somehow somewhere I've got to choose.
No matter if it is win or lose.
Floor 7 Posted 2003-10-05 00:00 ·  中国 湖北 荆门 京山市 电信
初级用户
Credits 183
Posts 15
Joined 2003-07-07 00:00
22-year member
UID 6493
Gender Male
Status Offline
Regarding issue A, I mainly want to find materials about a certain record under DOS. For example, when using GHOST in an internet café, the username and IP are the same. So as long as I first use a tool to obtain the MAC address, then look up the record about the MAC address, I can get the IP, computer name, etc. This can have a greater role in diskless PXE. Regarding issue B, eval.exe can achieve it, but it doesn't assign a value to the variable. Maybe I didn't use it correctly. Please everyone think of a way.
Floor 8 Posted 2003-10-15 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 huaqingyuan:

Regarding question A, because I don't know your specific requirements, I only wrote a general framework. If it needs to meet your requirements, some details should be modified.

Regarding question B, the code I provided is a general way to save the command output result as an environment variable. Of course, there are other solutions, but this one is simpler; as for the details of eval.exe, I'm not very clear.

The following appends the source codes of the two. For the complete content, please download the file Open the attachment (I'm using the file upload function for the first time, please forgive me if there is an error)

::OP.BAT
@ECHO OFF
SET TABLE=sample.dat
IF == GOTO OPHELP
IF NOT EXIST %TABLE% GOTO OPERROR1

:OPMAIN
FIND " %1 " %TEMP%\RECORD.BAT
IF NOT ERRORLEVEL 1 GOTO OPLIST
IF NOT ERRORLEVEL 2 GOTO OPAPPEND
GOTO OPERROR2

:OPLIST
ECHO Record "%1" matched.
ECHO.
ECHO >%1.BAT @ECHO OFF
ECHO >>%1.BAT ECHO 姓名: %1
ECHO >>%1.BAT ECHO 姓别: %%1
ECHO >>%1.BAT ECHO 年龄: %%2
ECHO >>%1.BAT ECHO 爱好: %%3 %%4 %%5 %%6 %%7 %%8 %%9
CALL %TEMP%\RECORD.BAT
ECHO.
ECHO Record "%1" displayed.
DEL %TEMP%\RECORD.BAT
DEL %1.BAT
GOTO OPEND

:OPAPPEND
ECHO Record "%1" NOT matched!
ECHO.
IF == GOTO OPEND
ECHO %1 %2 %3 %4 %5 %6 %7 %8 %9 >> %TABLE%
ECHO.
ECHO Record "%1" appended.
GOTO OPEND

:OPHELP
ECHO.
ECHO Sample of Table Operation.
ECHO Usage: %0 record-key
ECHO or: %0 record-key data1 data2 data3
ECHO.
GOTO OPEND

:OPERROR1
ECHO.
ECHO Data file "%TABLE%" NOT exist!
ECHO.
GOTO OPEND

:OPERROR1
ECHO.
ECHO Failed to match record "%1"!
ECHO.
GOTO OPEND

:OPEND
SET TABLE=

::GETVALUE.BAT
@ECHO OFF
IF NOT == GOTO GVMAIN
:GVHELP
ECHO.
ECHO Get result of command with environment variable.
ECHO Usage: %0 command
ECHO Exaple: %0 CD
ECHO.
GOTO GVEND

:GVMAIN
SET COMMAND=%1 %2 %3 %4 %5 %6 %7 %8 %9
COPY SETENV.DAT %TEMP%\SETENV.BAT > NUL
%COMMAND% >> %TEMP%\SETENV.BAT
CALL %TEMP%\SETENV.BAT
IF == GOTO GVEND
ECHO Value of variable is %#VAR#%.
DEL %TEMP%\SETENV.BAT
SET COMMAND=
SET #VAR#=

:GVEND









※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 9 Posted 2003-10-26 00:00 ·  中国 湖北 荆门 京山市 电信
初级用户
Credits 183
Posts 15
Joined 2003-07-07 00:00
22-year member
UID 6493
Gender Male
Status Offline
Thanks
Floor 10 Posted 2003-10-26 00:00 ·  中国 湖北 荆门 京山市 电信
初级用户
Credits 183
Posts 15
Joined 2003-07-07 00:00
22-year member
UID 6493
Gender Male
Status Offline
Because I had something to do before and didn't see the post, today I saw it and tried it. There seems to be something wrong with the part of adding records about problem A. Maybe I don't know how to use it. Please, Brother willsort, let me know.
Floor 11 Posted 2003-10-31 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:

Sorry, there was a small problem with the source program. It's my fault for not debugging properly. Here is the modified file attached: Open attachment

If there are any other questions, please let me know in time.


※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 12 Posted 2003-11-17 00:00 ·  中国 黑龙江 大庆 联通
初级用户
Credits 183
Posts 15
Joined 2003-07-07 00:00
22-year member
UID 6493
Gender Male
Status Offline
Thanks again to willsort, you are indeed a master of batch processing
Floor 13 Posted 2003-11-17 00:00 ·  中国 黑龙江 大庆 联通
初级用户
Credits 183
Posts 15
Joined 2003-07-07 00:00
22-year member
UID 6493
Gender Male
Status Offline
The modified file can't be downloaded now. Can you just paste it here directly? Thanks.
Floor 14 Posted 2003-11-19 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: huaqingyuan:

I have made modifications to the code in the original post. The main points are as follows:

1. In the fourth sentence of :OPAPPEND, an extra space is added after ECHO;
Mainly to pass FIND " %1 ", to avoid mis-matching ABCD and BCD;

2. The reference mark of the variable string is changed from single quotes to double quotes;
The forum seems to handle single quotes in a special way, always displaying them twice, which has no impact on the original code;

3. Some other spelling errors;
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Forum Jump: