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 12:12
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to write P processing that meets this function View 2,271 Replies 17
Original Poster Posted 2007-08-07 16:20 ·  中国 广东 广州 白云区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
In the process of data processing (C:\123\Many.TXT files), I urgently need a P processing that can achieve the following functions. Please help!

1> The third line is the same
2> The first line is greater than or equal to
3> The second line is greater than. The.txt files are moved to C:\456, as follows. B.txt should be moved.

Note: (The characters to be compared in the first, second, and third lines are all variables, and within the same line, they are separated by the TAB key)

The following are part of the contents of two.txt files.

A.txt

Date 06/29/07
Time 08:16:26
Serial # ML07300010JEB
Script file 2820.scr
Station GXHCDG02
PASSED

CAPTURED TARS DATA
LABEL VALUE
AssyNum W10130544
GDS_ErrTmp 0x00
WaterBeforeReload 0x00b5
HVDC_LO_Byte 0x0136
GDS_ErrTmp 0x00

B.txt

Date 06/30/07
Time 08:19:30
Serial # ML07300010JEB
Script file 2820.scr
Station GXHCDG02
PASSED

CAPTURED TARS DATA
LABEL VALUE
AssyNum W10130544
GDS_ErrTmp 0x00
WaterBeforeReload 0x00b5
HVDC_LO_Byte 0x0136
GDS_ErrTmp 0x00

[ Last edited by joshualaw on 2007-8-7 at 09:50 PM ]
Floor 2 Posted 2007-08-07 17:46 ·  中国 广东 广州 白云区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
Originally posted by 26933062 at 2007-8-7 05:34 PM:
Which file's content is used for comparison?
Compare all with the content of a.txt?


No, the object is between any Txt files in C:\123\, first compare the third line, only after they are completely the same, then compare the first line and the second line,
Floor 3 Posted 2007-08-07 21:46 ·  中国 广东 广州 黄埔区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
Originally posted by 26933062 at 2007-8-7 06:03 PM:
Oh my god,
After you extract any file from the C:\123 folder, which one are you going to compare the first, second, and third lines with???
---》Because there are at least two files in the C:\123 folder that have the same third line but different first and second lines. Therefore, compare between them and move out the ones that meet the conditions.

Also, what you should be comparing is the part you colored?
---》Yes, compare the colored parts of the first, second, and third lines respectively

Also, in your first line...

---》The last 07 is the year, to avoid confusion, I wrote the date format of the first line here, mm/dd/yy

Sorry, maybe I didn't express it well. Please take another look at my colored reply.

[ Last edited by joshualaw on 2007-8-7 at 09:48 PM ]
Floor 4 Posted 2007-08-08 11:11 ·  中国 广东 广州 白云区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
First of course I'm grateful for your enthusiasm, but it still can't run now. The errors are as follows,

Now the problem is, if there are more than 3 files with the same content in the third line. How to judge the content of the first and second lines?
For example: 4.txt, 5.txt and 6.txt
After comparing 4.txt and 5.txt, 5.txt meets your requirements and will be moved. Then what about 6.txt? Do we still need to compare it with 4.txt?
Yes, as long as the third line is the same, compare the first and second lines two by two. In short, move out those with the same third line, the first line greater than or equal to, and the second line greater than (the date and time are closer to the most recent),
Attachments
nodefine.jpg
Floor 5 Posted 2007-08-08 19:38 ·  中国 广东 广州 黄埔区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
What I understand is: The first line is the date, the second line is the time. When comparing, if the first line is greater, there's no need to compare the second line anymore, right? If the first line is equal, then compare the second line, is that so?
-->Yes
There's another question: If there are three or more files with the third line the same, and the first lines of content are 07/20/07, 07/25/07, 07/30/07 respectively, what should be done? Move the file with 07/30/07, then do the remaining two need to be compared again?
-->Then move 07/25/07. If both are 07/20/07, then look at which has the larger second line time and move that one

Now I have attached this folder, which has 10 TXT files. The third lines of the three files 14103806.txt, 45678912.txt, and 123455675.txt are all the same

1》When P processes the first run, move 14103806.txt first because its first line date is 06/15/07,

2》When P processes the second run, move 123455675.txt again because their first line dates are the same, both 06/14/07, but the second line time 10:37:20 >10:36:48

The above English means that the variable - + -1 is not defined. Now I hope you can understand it more clearly. First, thank you!

[ Last edited by joshualaw on 2007-8-10 at 11:05 PM ]
Floor 6 Posted 2007-08-08 22:56 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Finally got it......

The above code is okay. The problem is that you said that each line is separated by tabs, but in fact, the space in front of the # in your third line is a space, not a tab, and the problem is here.

The file you uploaded is moved by this batch file: 14103806.txt and 123455675.txt files, no need to run twice.

Is this the effect you want?

The following code was tested successfully on my side. It can handle file names with spaces.

.]


@echo off&set a=1&set b=1&set c=1&set sst=0
setlocal ENABLEDELAYEDEXPANSION
for /f "delims=" %%a in ('dir/b *.txt') do call :ss "%%a"

rem +Third line content = file name
for /f "tokens=1-4 delims=_=" %%a in ('set _') do set +%%d=!+%%d!_%%a

rem __Serial number = file name First line content Second line content
for /f "tokens=2* delims=_" %%a in ('set +') do (
if not "%%b"=="" set __!a!=%%a_%%b&set/a asd+=1
)
set __>nul 2>nul||echo.&&echo No files to be moved&&echo.&&pause&&exit

:loop
for /f "tokens=1* delims==_" %%a in ('set __!b!') do set qua=%%b
:loop_
for /f "tokens=1 delims=_" %%i in ("!qua!") do set qua1="%%i"
set/a sst+=1
for /f "tokens=1-3 delims=" %%c in (!qua1!) do (
if !sst! neq 1 (call :duibi "%%c" %%d %%e) else set wjm="%%c"&set dyh=%%d&set deh=%%e
)
set qua1=!qua1:"=!
if "!qua:~0,1!"=="_" set qua=!qua:~1!
if not "!qua:_=!"=="!qua1!" call set qua=!!qua:%qua1%=!!&goto loop_
set /a c+=1&set /a b+=1
if defined __!b! goto loop

rem Move files
if not exist c:\456 md c:\456
cls&echo\&echo The following are the files to be moved soon......&echo\
for /f "tokens=2 delims==" %%a in ('set ok^|sort') do (
echo %%a
move %%a c:\456
)
pause
start "" "c:\456"
exit

rem Set the specified content of the first three lines of the file as variables Format: _file name = first line content Second line content Third line content
:ss
set ls=0
rem If the operation is not successful, delete the space after delims= in the following line and enter a tab key.
for /f "tokens=2 delims= " %%b in ('findstr .* %1') do (
set/a ls+=1
if !ls! lss 4 (set "_%~1=!_%~1!_%%b") else goto :eof
)

rem Judge date and time
:duibi
rem echo %1 %2 %3 == !wjm! !dyh! !deh!
set xx1=%1&set xx2=%2&set xx3=%3
set/a ook+=1
if "!dyh!"=="%2" (
if !deh! leq %3 (set ok!ook!=%1) else (call :pan)
goto :eof
)
for /f "tokens=1-3 delims=/" %%o in ("!dyh!") do set nian=%%q&set yue=%%o&set ri=%%p
for /f "tokens=1-3 delims=/" %%o in ("%2") do (
if !nian! gtr %%q (
call :pan
goto :eof
)
if !nian! lss %%q set ok!ook!=%1&goto :eof
if !yue! gtr %%o (
call :pan
goto :eof
)
if !yue! lss %%o set ok!ook!=%1&goto :eof
if !ri! gtr %%p (
call :pan
goto :eof
)
if !ri! lss %%p set ok!ook!=%1&goto :eof
)
goto :eof
:pan
set ok!ook!=!wjm!
set wjm=!xx1!&set dyh=!xx2!&set deh=!xx3!
goto :eof


[ Last edited by 26933062 on 2007-8-9 at 04:47 AM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
joshualaw +2 2007-08-09 07:48
Floor 7 Posted 2007-08-08 22:56 ·  中国 福建 泉州 晋江市 电信
新手上路
Credits 9
Posts 4
Joined 2007-05-14 22:34
19-year member
UID 88549
Gender Male
Status Offline
Floor 8 Posted 2007-08-08 23:05 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
The part at the end of the code is for judging the date and time. It feels a bit messy. I would like to ask all the experts if there is a simpler way to judge.
For example, judge which date is larger between 05/30/2007 and 07/20/2007?
Judge which time is earlier between 18:20:08 and 09:05:12?
I split the date with for to judge.
For the time part, it is directly judged.
For example: if 18:20:08 gtr 09:05:12 echo ok
I wonder if it will go wrong in some cases.
Floor 9 Posted 2007-08-09 08:05 ·  中国 广东 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
Originally posted by 26933062 at 2007-8-8 10:56 PM:
Finally, it's done......
The above code is okay. The problem is that you said each line is separated by a tab, but in fact, the space before the # in the third line is not a tab, and the problem lies here...



Hard work, amazing. All functions can be realized. First, thank you. But there is a small requirement as follows. Let's see if it can be done.

Finally, it's done......
The above code is okay. The problem is that you said each line is separated by a tab, but in fact, the space before the # in the third line is not a tab, and the problem lies here.
The file you uploaded is moved by this batch file as 14103806.txt and 123455675.txt, which is moved at one time, without running twice. That is to say, after running the batch file, all files with the same third line content and the earliest first line date (if the dates are the same, the earliest second line time) will be moved. Only one file is left.
Is this the effect?
----->Can the files moved for the first time, second time, third time..... be moved to different folders under c:\456 respectively? For example: C:\456\1\14103806.txt, C:\456\2\123455675.txt. If it can be done like this, this processing will be more perfect and convenient for processing. Thank you.
Floor 10 Posted 2007-08-09 09:06 ·  中国 山西 运城 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
26楼的代码,可以将整理格式后的两个日期分别放入两个变量中进行比较就可以了,完全没有必要对年月日分别进行比较。Special format date comparison: Just unify them into one format in advance and then compare. For example, the code on floor 6: You can put the two sorted dates into two variables respectively for comparison, and there is absolutely no need to compare the year, month and day respectively.
Floor 11 Posted 2007-08-09 09:59 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
It should be okay, but it's not in chronological order. Is that acceptable?
Then you mean you have to create as many folders in c:\123 as the number of files moved? Need to think about it... No time now, I'll think about it when I have time.
Floor 12 Posted 2007-08-09 10:04 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
Brother on floor 10, I used the following method to judge the date and made a mistake. Is the method wrong?
@echo off
set a=05/30/2006
set b=05/25/2007
if %a% lss %b% (echo aaa 小) else echo aaa 大
pause
Floor 13 Posted 2007-08-13 20:46 ·  中国 广东 广州 黄埔区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
Brother 26933062:

Can you take some time to improve it? Just meet either of the following two conditions.

1》Move the files moved each time into different folders under C:\456, for example: c:\456\11\contains the files moved for the first time c:\456\22\contains the files moved for the second time c:\456\33\contains the files moved for the third time, at most moved three times

2》Move only one each time.

Thanks!

[ Last edited by joshualaw on 2007-8-13 at 08:48 PM ]
Floor 14 Posted 2007-08-16 07:56 ·  中国 广东 广州 番禺区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
Brother 26933062:

Can you please take some time to improve it so that each time only one is moved over?

Thanks!
Floor 15 Posted 2007-08-16 08:32 ·  中国 山西 运城 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
Reply to floor 12

That's because your date format is not uniformly arranged correctly.
Arrange it in the order of year, month, and day,
and there will be no problem when comparing.

Actually, this is comparing strings,
not numeric strings,
because there are invalid numbers (such as /) in the strings being compared,
but the achieved effect is similar.

For safety, you can add 0 prefixes for alignment to months and days.
Time comparison is also similar,
as long as it is ensured that the larger time unit comes first.
Forum Jump: