中国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-09-23 13:03
47,812 topics / 349,917 posts / today 0 new / 48,273 members
DOS批处理 & 脚本技术(批处理室) » [Help] Batch processing problem, humbly asking experts for advice?[Help]
Printable Version  2,723 / 13
Floor1 huaqingyuan Posted 2003-10-01 00:00
初级用户 Posts 15 Credits 183
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




Floor2 huaqingyuan Posted 2003-10-02 00:00
初级用户 Posts 15 Credits 183
Does nobody know?
Floor3 iceboy Posted 2003-10-02 00:00
银牌会员 Posts 512 Credits 1,681
It seems that debug needs to be used, and the easiest way is to use QB/C
Floor4 huaqingyuan Posted 2003-10-02 00:00
初级用户 Posts 15 Credits 183
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
Floor5 huaqingyuan Posted 2003-10-04 00:00
初级用户 Posts 15 Credits 183
Where are the experts? Come out and help!, this will be very useful when done
Floor6 iceboy Posted 2003-10-04 00:00
银牌会员 Posts 512 Credits 1,681
First, let's talk about your idea. Maybe we can try another way to do it.
Floor7 huaqingyuan Posted 2003-10-05 00:00
初级用户 Posts 15 Credits 183
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.
Floor8 willsort Posted 2003-10-15 00:00
元老会员 Posts 1,512 Credits 4,432
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









Floor9 huaqingyuan Posted 2003-10-26 00:00
初级用户 Posts 15 Credits 183
Thanks
Floor10 huaqingyuan Posted 2003-10-26 00:00
初级用户 Posts 15 Credits 183
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.
Floor11 willsort Posted 2003-10-31 00:00
元老会员 Posts 1,512 Credits 4,432
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.


Floor12 huaqingyuan Posted 2003-11-17 00:00
初级用户 Posts 15 Credits 183
Thanks again to willsort, you are indeed a master of batch processing
Floor13 huaqingyuan Posted 2003-11-17 00:00
初级用户 Posts 15 Credits 183
The modified file can't be downloaded now. Can you just paste it here directly? Thanks.
Floor14 willsort Posted 2003-11-19 00:00
元老会员 Posts 1,512 Credits 4,432
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;
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023