|
joshualaw
初级用户
 
积分 132
发帖 62
注册 2007-6-5
状态 离线
|
『楼 主』:
符合这一功能的P处理怎样写.
使用 LLM 解释/回答一下
在数据处理过程中 (C:\123\很多.TXT 文件), 本人急求能实现下列功能的P 处理, 请帮忙啊!
1> 第三行相同
2> 第一行大于或等于
3> 第二行大于 的.txt文件,移到C:\456,如下.应移B.txt
注: (第一, 二和三行要比较的字符,全部都是变量, 同一行之间是以TAB键为分隔)
下面是两个.txt文件的部分内容.
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 ]
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 ]
|
|
2007-8-7 16:20 |
|
|
joshualaw
初级用户
 
积分 132
发帖 62
注册 2007-6-5
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
Originally posted by 26933062 at 2007-8-7 05:34 PM:
问题是用哪个文件的内容来比较?
全部都跟a.txt的内容比吗?
不是, 对象是C:\123\ 任意Txt文件之间, 先比较第三行, 只有完全相同后,再比较第一行和第二行,
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,
|
|
2007-8-7 17:46 |
|
|
joshualaw
初级用户
 
积分 132
发帖 62
注册 2007-6-5
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
Originally posted by 26933062 at 2007-8-7 06:03 PM:
我晕,
你从C:\123文件夹里任意提取一个文件后,要把它的第一,二,三行和谁对比???
---》因为在C:\123文件夹里含有第三行相同,且第一,二,行不同的文件至少有两个以上,因此在它们之间互相比较,把符合条件的移出来。
还有就是你要对比的应该是你上了颜色的部分吧?
---》是的,分别比较第一,二,三行带有颜色的部分
还有你的第一行内 ...
---》 最后的那个07是年,为了不引起混淆,我把第一行的 date 格式写在这,mm/dd/yy
不好意思,或许我没表达好啊,请再看看我的带有颜色的回复,
Last edited by joshualaw on 2007-8-7 at 09:48 PM ]
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 ]
|
|
2007-8-7 21:46 |
|
|
joshualaw
初级用户
 
积分 132
发帖 62
注册 2007-6-5
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
首先谢谢你的热心啊, 但现在还不能运行呢, 错误如下,
现在的问题是,如果有3个以上的文件第三行内容相同.该如何判断第一,二行的内容?
如:4.txt和5.txt和6.txt
对比4.txt和5.txt以后,5.txt符合你的要求,即将被移走.那么6.txt该怎么办?还要继续和4.txt对比吗?
是, 只要第三行相同, 两个两个比第一,二行,总之, 把第三行相同,第一行大于或等于,第二行大于的移出来(日期,时间靠近最近的),
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),
附件
1: nodefine.jpg (2007-8-8 11:11, 8.86 KiB,下载次数: 3)
|
|
2007-8-8 11:11 |
|
|
joshualaw
初级用户
 
积分 132
发帖 62
注册 2007-6-5
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
我理解的是: 你的第一行是日期,第二行是时间,在对比的时候,如果第一行大于,就不用再比第二行了,是吗? 如果第一行等于,就再比第二行,是这样的吗?
-->是的
还有个问题就是,如果有三个或三个以上的文件第三行都相同,而第一行的内容分别是,07/20/07 07/25/07 07/30/07 该怎么办?是将07/30/07的文件移走,那剩下的两个还要再比吗?
-->再移07/25/07,如两个都是07/20/07,就看第二行时间谁最大就移谁啊
现我附上了这一文件夹,里面有10 TXT文件,文件 14103806.txt,45678912.txt 和 123455675.txt 这三个文件的第三行都相同
1》P 处理第一次运行时,先移走14103806.txt,因为它的第一行日期是 06/15/07,
2》P 处理第二次运行时,再移走123455675.txt,因为它们的第一行日期相同,都是06/14/07,但第二行时间10:37:20 >10:36:48
上面的英文是说,变量 - + -1 没有定义啊。现希望你能更明白啊,先辛苦了, 谢谢!
Last edited by joshualaw on 2007-8-10 at 11:05 PM ]
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 ]
|
|
2007-8-8 19:38 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
终于搞定了......
上面的代码没问题的,问题出在你说每行之间是用tab分隔的,但是事实上你的第三行内容#号前面是空格,不是tab,问题就出在这里.
你上传的文件用这个批处理移走的是14103806.txt和123455675.txt文件, 是一次性移走的,不用运行两次. 也就是说运行批处理后会将第三行内容相同的,第一行日期最近的(若日期相同,就是第二行时间最近的)文件全部移走.只留下一个文件.
是要这个效果吗?
以下代码在我这里测试成功.以可以处理含空格的文件名.
文件名及前三行文件内容不能含有特殊字符,和_这三个符号.
@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 +第三行内容=文件名
for /f "tokens=1-4 delims=_=" %%a in ('set _') do set +%%d=!+%%d!_%%a
rem __序号=文件名 第一行内容 第二行内容
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 没有需要移走的文件&&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 移动文件
if not exist c:\456 md c:\456
cls&echo\&echo 以下是即将被移走的文件......&echo\
for /f "tokens=2 delims==" %%a in ('set ok^|sort') do (
echo %%a
move %%a c:\456
)
pause
start "" "c:\456"
exit
rem 将文件的前三行指定内容设为变量 格式: _文件名=第一行内容 第二行内容 第三行内容
:ss
set ls=0
rem 如果运行不成功,就将下面这行的delims=后面的空格删除,输入一个tab键即可.
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 进行日期和时间的判断
: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 ]
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 ]
|
|
2007-8-8 22:56 |
|
|
island008
新手上路

积分 9
发帖 4
注册 2007-5-14
状态 离线
|
|
2007-8-8 22:56 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
代码最后的部分是判断日期和时间的,感觉有些乱,请教各位高手有没有简单一点的判断方法.
如判断 05/30/2007 和 07/20/2007 哪个日期大?
判断 18:20:08 和 09:05:12 哪个时间早?
我是用for将日期分割开来判断的.
时间部分就是直接判断的,
如: if 18:20:08 gtr 09:05:12 echo ok
不知道会不会在某种情况下出错.
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.
|
|
2007-8-8 23:05 |
|
|
joshualaw
初级用户
 
积分 132
发帖 62
注册 2007-6-5
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
Originally posted by 26933062 at 2007-8-8 10:56 PM:
终于搞定了......
上面的代码没问题的,问题出在你说每行之间是用tab分隔的,但是事实上你的第三行内容#号前面是空格,不是tab,问题就出 ...
辛苦了,高啊,所有功能可以实现啦,先谢谢,但还有一点小小的要求如下,看看能否做的到啊。
终于搞定了......
上面的代码没问题的,问题出在你说每行之间是用tab分隔的,但是事实上你的第三行内容#号前面是空格,不是tab,问题就出在这里.
你上传的文件用这个批处理移走的是14103806.txt和123455675.txt文件,是一次性移走的,不用运行两次.也就是说运行批处理后会将第三行内容相同的,第一行日期最近的(若日期相同,就是第二行时间最近的)文件全部移走.只留下一个文件.
是要这个效果吗?
-----> 能否把第一次,第二次,第三次.....移出的文件,分别移到 c:\456下的不同的文件夹里呢,如: C:\456\1\14103806.txt ,C:\456\2\123455675.txt, 能做到这样的话,这一P处里更加完美和方便处里啊, 谢了,
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.
|
|
2007-8-9 08:05 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
26933062
特殊格式日期比较
只需要将他们预先统一为一种格式再进行比较就可以了
如6楼的代码
可以将整理格式后的两个日期分别放入两个变量中进行比较就可以了
完全没有必要对年月日分别进行比较
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.
|
|
2007-8-9 09:06 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
应该可以,不过不是按时间顺序排的,可以吗?
那样你不是,总共移走多少个文件,就要在c:\123里建多少个文件夹?还要想想...现在没时间,有空帮你想.
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.
|
|
2007-8-9 09:59 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
10 楼的兄弟,我用以下方法判断日期出错,请问是方法错了吗?
@echo off
set a=05/30/2006
set b=05/25/2007
if %a% lss %b% (echo aaa 小) else echo aaa 大
pause
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
|
|
2007-8-9 10:04 |
|
|
joshualaw
初级用户
 
积分 132
发帖 62
注册 2007-6-5
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
26933062 兄:
能否帮忙抽空完善一下,只要达到下面二个中的任意一个就行。
1》把每次移过去的文件,分别移到C:\456 下的不同文件夹里啊,如:c:\456\11\包含第一次移来的文件 c:\456\22\包含第二次移来的文件 c:\456\33\包含第三次移来的文件,至多移三次
2》每次只要移一个过去。
谢!
Last edited by joshualaw on 2007-8-13 at 08:48 PM ]
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 ]
|
|
2007-8-13 20:46 |
|
|
joshualaw
初级用户
 
积分 132
发帖 62
注册 2007-6-5
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
26933062 兄:
能否帮忙抽空完善一下,使之每次只要移一个过去啊。
谢!
Brother 26933062:
Can you please take some time to improve it so that each time only one is moved over?
Thanks!
|
|
2007-8-16 07:56 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
回应12楼
那是你的日期格式统一的有问题
将它按年月日的顺序排列
在进行比较就不会有问题了
实际上这是对字符串进行比较
而不是对数字串进行比较
因为它所比较的串中存在无效数字(比如/)
不过所实现的效果是类似的
保险起见可以给月日都加上对齐用的0前缀
时间比较也同样类似
只要保证越大的时间单位越靠前就可以了
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.
|
|
2007-8-16 08:32 |
|
|