|
quan_zhou
初级用户
 
积分 190
发帖 40
注册 2005-3-17
状态 离线
|
『楼 主』:
如果將1文本的1組溫度記錄值的最大值找出,并加以判斷
使用 LLM 解释/回答一下
如果將1文本的1組溫度記錄值的最大值找出,并加以判斷如:若大於45,小於90顯示OK,否就顯示NG, 運行環境為 XP SP2,用批處理或VBS腳本能實現這工功能就行了,請大家幫忙看看,我用FOR試了不行,應該是我不會用。
文本內容如下:
--------1.txt---------------
New logging session started at : 04:57:57
Your product Upper Temperature Limit is : 115 C.
04:57:57 | CT : 76 C AT : 0 C
04:58:02 | CT : 76 C AT : 0 C
04:58:07 | CT : 76 C AT : 0 C
04:58:12 | CT : 76 C AT : 0 C
04:58:17 | CT : 76 C AT : 0 C
04:58:22 | CT : 76 C AT : 0 C
04:58:27 | CT : 76 C AT : 0 C
04:58:32 | CT : 76 C AT : 0 C
04:58:37 | CT : 76 C AT : 0 C
04:58:42 | CT : 76 C AT : 0 C
04:58:47 | CT : 76 C AT : 0 C
04:58:52 | CT : 76 C AT : 0 C
04:58:57 | CT : 76 C AT : 0 C
04:59:02 | CT : 76 C AT : 0 C
04:59:07 | CT : 77 C AT : 0 C
04:59:12 | CT : 77 C AT : 0 C
04:59:17 | CT : 83 C AT : 0 C
04:59:22 | CT : 77 C AT : 0 C
04:59:27 | CT : 77 C AT : 0 C
04:59:32 | CT : 77 C AT : 0 C
04:59:37 | CT : 77 C AT : 0 C
04:59:42 | CT : 82 C AT : 0 C
04:59:47 | CT : 78 C AT : 0 C
04:59:52 | CT : 86 C AT : 0 C
04:59:57 | CT : 89 C AT : 0 C
05:00:02 | CT : 90 C AT : 0 C
05:00:07 | CT : 91 C AT : 0 C
05:00:12 | CT : 93 C AT : 0 C
05:00:17 | CT : 93 C AT : 0 C
05:00:22 | CT : 94 C AT : 0 C
05:00:27 | CT : 95 C AT : 0 C
05:00:32 | CT : 95 C AT : 0 C
05:00:37 | CT : 96 C AT : 0 C
05:00:42 | CT : 97 C AT : 0 C
05:00:47 | CT : 97 C AT : 0 C
05:00:52 | CT : 98 C AT : 0 C
05:00:57 | CT : 98 C AT : 0 C
05:01:02 | CT : 99 C AT : 0 C
05:01:07 | CT : 100 C AT : 0 C
05:01:12 | CT : 100 C AT : 0 C
05:01:17 | CT : 102 C AT : 0 C
05:01:22 | CT : 105 C AT : 0 C
05:01:27 | CT : 106 C AT : 0 C
05:01:32 | CT : 108 C AT : 0 C
05:01:37 | CT : 101 C AT : 0 C
05:01:42 | CT : 99 C AT : 0 C
05:01:48 | CT : 101 C AT : 0 C
05:01:53 | CT : 102 C AT : 0 C
05:01:58 | CT : 110 C AT : 0 C
05:02:03 | CT : 112 C AT : 0 C
05:02:08 | CT : 114 C AT : 0 C
05:02:13 | CT : 113 C AT : 0 C
05:02:18 | CT : 114 C AT : 0 C
05:02:23 | CT : 114 C AT : 0 C
05:02:28 | CT : 114 C AT : 0 C
05:02:33 | CT : 116 C AT : 0 C
05:02:38 | CT : 116 C AT : 0 C
05:02:43 | CT : 117 C AT : 0 C
05:02:48 | CT : 118 C AT : 0 C
05:02:53 | CT : 119 C AT : 0 C
-----------------------------------------------------
溫度監測越久,文本內空就越多。
Last edited by quan_zhou on 2007-5-12 at 03:44 PM ]
If you want to find the maximum value of a set of temperature records in a text and make a judgment: if it is greater than 45 and less than 90, display OK; otherwise, display NG. The running environment is XP SP2, and it can be achieved with batch processing or VBS scripts. Please help take a look. I tried with FOR but it didn't work. It should be that I don't know how to use it.
The text content is as follows:
--------1.txt---------------
New logging session started at : 04:57:57
Your product Upper Temperature Limit is : 115 C.
04:57:57 | CT : 76 C AT : 0 C
04:58:02 | CT : 76 C AT : 0 C
04:58:07 | CT : 76 C AT : 0 C
04:58:12 | CT : 76 C AT : 0 C
04:58:17 | CT : 76 C AT : 0 C
04:58:22 | CT : 76 C AT : 0 C
04:58:27 | CT : 76 C AT : 0 C
04:58:32 | CT : 76 C AT : 0 C
04:58:37 | CT : 76 C AT : 0 C
04:58:42 | CT : 76 C AT : 0 C
04:58:47 | CT : 76 C AT : 0 C
04:58:52 | CT : 76 C AT : 0 C
04:58:57 | CT : 76 C AT : 0 C
04:59:02 | CT : 76 C AT : 0 C
04:59:07 | CT : 77 C AT : 0 C
04:59:12 | CT : 77 C AT : 0 C
04:59:17 | CT : 83 C AT : 0 C
04:59:22 | CT : 77 C AT : 0 C
04:59:27 | CT : 77 C AT : 0 C
04:59:32 | CT : 77 C AT : 0 C
04:59:37 | CT : 77 C AT : 0 C
04:59:42 | CT : 82 C AT : 0 C
04:59:47 | CT : 78 C AT : 0 C
04:59:52 | CT : 86 C AT : 0 C
04:59:57 | CT : 89 C AT : 0 C
05:00:02 | CT : 90 C AT : 0 C
05:00:07 | CT : 91 C AT : 0 C
05:00:12 | CT : 93 C AT : 0 C
05:00:17 | CT : 93 C AT : 0 C
05:00:22 | CT : 94 C AT : 0 C
05:00:27 | CT : 95 C AT : 0 C
05:00:32 | CT : 95 C AT : 0 C
05:00:37 | CT : 96 C AT : 0 C
05:00:42 | CT : 97 C AT : 0 C
05:00:47 | CT : 97 C AT : 0 C
05:00:52 | CT : 98 C AT : 0 C
05:00:57 | CT : 98 C AT : 0 C
05:01:02 | CT : 99 C AT : 0 C
05:01:07 | CT : 100 C AT : 0 C
05:01:12 | CT : 100 C AT : 0 C
05:01:17 | CT : 102 C AT : 0 C
05:01:22 | CT : 105 C AT : 0 C
05:01:27 | CT : 106 C AT : 0 C
05:01:32 | CT : 108 C AT : 0 C
05:01:37 | CT : 101 C AT : 0 C
05:01:42 | CT : 99 C AT : 0 C
05:01:48 | CT : 101 C AT : 0 C
05:01:53 | CT : 102 C AT : 0 C
05:01:58 | CT : 110 C AT : 0 C
05:02:03 | CT : 112 C AT : 0 C
05:02:08 | CT : 114 C AT : 0 C
05:02:13 | CT : 113 C AT : 0 C
05:02:18 | CT : 114 C AT : 0 C
05:02:23 | CT : 114 C AT : 0 C
05:02:28 | CT : 114 C AT : 0 C
05:02:33 | CT : 116 C AT : 0 C
05:02:38 | CT : 116 C AT : 0 C
05:02:43 | CT : 117 C AT : 0 C
05:02:48 | CT : 118 C AT : 0 C
05:02:53 | CT : 119 C AT : 0 C
-----------------------------------------------------
The longer the temperature monitoring is, the more content there is in the text.
Last edited by quan_zhou on 2007-5-12 at 03:44 PM ]
|
|
2007-5-12 14:41 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
@echo off&setlocal enabledelayedexpansion
set a=0
for /f "tokens=5" %%i in (1.txt) do if %%i GTR !a! set a=%%i
if %a% GTR 45 (goto label) else (echo NG)
:label
if %a% LSS 90 (echo OK) else (echo NG)
pause
试试?
```@echo off&setlocal enabledelayedexpansion
set a=0
for /f "tokens=5" %%i in (1.txt) do if %%i GTR !a! set a=%%i
if %a% GTR 45 (goto label) else (echo NG)
:label
if %a% LSS 90 (echo OK) else (echo NG)
pause
```
|
|
2007-5-12 15:41 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
如果文本有
New logging session started at : 04:57:57
Your product Upper Temperature Limit is : 115 C.
应跳过4行.
@echo off&setlocal enabledelayedexpansion
set a=0
for /f "skip=4 tokens=5" %%i in (1.txt) do if %%i GTR !a! set a=%%i
if %a% GTR 45 (goto label) else (echo NG)
:label
if %a% LSS 90 (echo OK) else (echo NG)
pause
If the text has
New logging session started at : 04:57:57
Your product Upper Temperature Limit is : 115 C.
Should skip 4 lines.
@echo off&setlocal enabledelayedexpansion
set a=0
for /f "skip=4 tokens=5" %%i in (1.txt) do if %%i GTR !a! set a=%%i
if %a% GTR 45 (goto label) else (echo NG)
:label
if %a% LSS 90 (echo OK) else (echo NG)
pause
|
|
2007-5-12 15:45 |
|
|
quan_zhou
初级用户
 
积分 190
发帖 40
注册 2005-3-17
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
非常感謝wudixin96兄的回復,您的代碼我測試OK,謝謝!
其實我接觸DOS也有好久了,但就沒法深入,真是沒用!
能否幫忙解釋您的代碼呢?
Thank you very much for brother wudixin96's reply. Your code I tested is OK, thank you! Actually, I have been in contact with DOS for a long time, but I can't go deep into it. It's really useless! Can you help explain your code?
|
|
2007-5-12 16:01 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
@echo off&setlocal enabledelayedexpansion
set a=0 /*用于存储最大的温度值,并初始化*/
for /f "skip=4 tokens=5" %%i in (1.txt) do if %%i GTR !a! set a=%%i /*skip=4跳过4行. 由于tokens=5.所以%%i中存储的是取到的温度值.可以在cmd里输入for /?来了解一下for的用法*/
if %a% GTR 45 (goto label) else (echo NG)
:label
if %a% LSS 90 (echo OK) else (echo NG)
pause
我不会解释了.我的文字功底很差的.抱歉 ^-^
@echo off&setlocal enabledelayedexpansion
set a=0 /*Used to store the maximum temperature value and initialize*/
for /f "skip=4 tokens=5" %%i in (1.txt) do if %%i GTR !a! set a=%%i /*skip=4 skips 4 lines. Since tokens=5, the temperature value is stored in %%i. You can enter for /? in cmd to learn about the usage of for*/
if %a% GTR 45 (goto label) else (echo NG)
:label
if %a% LSS 90 (echo OK) else (echo NG)
pause
I can't explain anymore. My writing skills are very poor. Sorry ^-^
|
|
2007-5-12 16:10 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 6 楼』:
Try gawk
使用 LLM 解释/回答一下
gawk "/CT/{if($5>45&&$5<90){print \"OK\"} else {print \"NG\" }}" 1.txt
```gawk "/CT/{if($5>45&&$5<90){print \"OK\"} else {print \"NG\" }}" 1.txt```
|
|
2007-5-12 16:15 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
gawk是Linux的东西吗?
Is gawk something related to Linux?
|
|
2007-5-12 16:18 |
|
|
zhoushijay
高级用户
    Autowalk
积分 845
发帖 375
注册 2007-3-3
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
set fso=createobject("scripting.filesystemobject")
set op=fso.opentextfile("1.txt",1)
set d=createobject("scripting.dictionary")
on error resume next
for i=1 to 1000
op.skipline
ln=op.readline
if len(ln)=39 then
t=mid(ln,17,2)
end if
if len(ln)=40 then
t=mid(ln,17,3)
end if
t=int(t)
if err=0 then
d.add i,t
end if
next
for each i in d
if d(i)>b then
mx=d(i)
end if
b=d(i)
next
if mx>45 and mx<90 then
msgbox("Temperature is OK"&chr(10)&"The hotest is "&mx&"C")
else
msgbox("Temperature is NG"&chr(10)&"The hotest is "&mx&"C")
end if
VBS版 ^^!
set fso=createobject("scripting.filesystemobject")
set op=fso.opentextfile("1.txt",1)
set d=createobject("scripting.dictionary")
on error resume next
for i=1 to 1000
op.skipline
ln=op.readline
if len(ln)=39 then
t=mid(ln,17,2)
end if
if len(ln)=40 then
t=mid(ln,17,3)
end if
t=int(t)
if err=0 then
d.add i,t
end if
next
for each i in d
if d(i)>b then
mx=d(i)
end if
b=d(i)
next
if mx>45 and mx<90 then
msgbox("Temperature is OK"&chr(10)&"The hotest is "&mx&"C")
else
msgbox("Temperature is NG"&chr(10)&"The hotest is "&mx&"C")
end if
VBS version ^^!
|

你好,脚本专家!
<a target=blank href=tencent://message/?uin=29654761&Site=www.111.com&Menu=yes><img border="0" SRC=http://wpa.qq.com/pa?p=1:29654761:5 alt="点击这里给我发消息"></a> |
|
2007-5-12 16:26 |
|
|
quan_zhou
初级用户
 
积分 190
发帖 40
注册 2005-3-17
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
TO zhoushijay 兄
您的代碼運行后都會顯"The hotest is* C" 不是文本中的最大溫度值。我試差改變1.TXT中內容試了幾次都是,謝謝大家的回復。
TO wudixin96k 兄
謝謝您的解釋,請問一下您代碼中的GTR 是否是小於、LSS是否是大於的意思? 因為我單獨測試了無效,如:
@echo off
set a=99
if %a% GTR 45 goto min
if %a% LSS 90 goto max
:min
顯示測試小於45
goto end
:max
顯示測試大於90
goto end
:end
TO zhoushijay Brother
After your code runs, it always shows "The hotest is* C", which is not the maximum temperature value in the text. I tried changing the content in 1.TXT several times, and it's always like that. Thank you everyone for your replies.
TO wudixin96k Brother
Thank you for your explanation. May I ask if GTR in your code means less than and LSS means greater than? Because I tested it separately and it didn't work. For example:
@echo off
set a=99
if %a% GTR 45 goto min
if %a% LSS 90 goto max
:min
Display test less than 45
goto end
:max
Display test greater than 90
goto end
:end
|
|
2007-5-12 17:06 |
|
|
zhoushijay
高级用户
    Autowalk
积分 845
发帖 375
注册 2007-3-3
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
是滴,我也发现问题了,正在努力修复之中
Yeah, I also found the problem and am working hard to fix it.
|

你好,脚本专家!
<a target=blank href=tencent://message/?uin=29654761&Site=www.111.com&Menu=yes><img border="0" SRC=http://wpa.qq.com/pa?p=1:29654761:5 alt="点击这里给我发消息"></a> |
|
2007-5-12 17:12 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
set /a 1/(var/45)&& set /a 1/(90/var)&& echo %var%
set /a 1/(var/45)&& set /a 1/(90/var)&& echo %var%
|
|
2007-5-12 17:14 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Originally posted by wudixin96 at 2007-5-12 16:18:
gawk是Linux的东西吗?
Linux 只是集成了这个工具,实际上它可以算是个编程语言,专业处理文本的程式语言。gawk是GNU版的awk。
想详细了解awk,可以去这里看看:
http://www.itisedu.com/phrase/200603021801255.html
Originally posted by wudixin96 at 2007-5-12 16:18:
Is gawk something related to Linux?
Linux only integrates this tool. Actually, it can be regarded as a programming language, a professional programming language for text processing. gawk is the GNU version of awk.
To learn more about awk in detail, you can take a look here:
http://www.itisedu.com/phrase/200603021801255.html
|
|
2007-5-12 17:18 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
Set fso = CreateObject("Scripting.FileSystemObject")
Set op = fso.OpenTextFile("1.txt",1)
Set d = CreateObject("Scripting.Dictionary")
on Error Resume Next '尽量少用……
For i = 1 To 1000 '建议使用AtEndOfStream...这样就不需要上面的错误忽略而且对于大于1000行的文本也可以处理
op.skipline '下面readline这里为什么要skip?
ln = op.ReadLine
If Len(ln) = 39 Then '以下用len和mid...建议学会用Instr...否则当长度不至2种的时候……
t = Mid(ln,17,2)
End If
If Len(ln) = 40 Then
t = Mid(ln,17,3)
End If
t = Int(t)
If Err = 0 Then
d.add i,t '还是老问题,为什么不用数组 d(i)=t,我不觉得用Dictionary对象有什么优势
End If
Next
For Each i In d '用的Dictionary,怎么变成数组了,汗~
If d(i) > b Then
mx = d(i)
End If
b = d(i)
Next
If mx > 45 And mx < 90 Then
MsgBox("Temperature is OK" & Chr(10) & "The hotest is " & mx & "C") '有常量不用非要用函数。Chr(10)=vbCr
Else
MsgBox("Temperature is NG" & Chr(10) & "The hotest is " & mx & "C") '不需要返回值的时候不要用括号
End If
'--缺少对对象的释放--
Set d = Nothing
Set op = Nothing
Set fso = Nothing
Last edited by slore on 2007-5-12 at 05:36 PM ]
Set fso = CreateObject("Scripting.FileSystemObject")
Set op = fso.OpenTextFile("1.txt",1)
Set d = CreateObject("Scripting.Dictionary")
on Error Resume Next 'Try to use less...
For i To 1000 'It is recommended to use AtEndOfStream... so that the above error ignoring is not needed and it can handle text with more than 1000 lines
op.skipline 'Why skip here before readline?
ln = op.ReadLine
If Len(ln) = 39 Then 'Use len and mid below... It is recommended to learn to use Instr... Otherwise, when the length is not only 2 types...
t = Mid(ln,17,2)
End If
If Len(ln) = 40 Then
t = Mid(ln,17,3)
End If
t = Int(t)
If Err = 0 Then
d.add i,t 'Still the old problem, why not use array d(i)=t, I don't think using Dictionary object has any advantages
End If
Next
For Each i In d 'Using Dictionary, how to become array, sweat~
If d(i) > b Then
mx = d(i)
End If
b = d(i)
Next
If mx > 45 And mx < 90 Then
MsgBox("Temperature is OK" & Chr(10) & "The hotest is " & mx & "C") 'Use constants instead of using functions. Chr(10)=vbCr
Else
MsgBox "Temperature is NG" & Chr(10) & "The hotest is " & mx & "C" 'Don't use parentheses when no return value is needed
End If
'--Lack of releasing objects--
Set d = Nothing
Set op = Nothing
Set fso = Nothing
Last edited by slore on 2007-5-12 at 05:36 PM ]
|
|
2007-5-12 17:22 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 14 楼』:
再将6楼的gawk命令改进一下
使用 LLM 解释/回答一下
gawk "BEGIN{max=0}/CT/{if($5>max)max=$5;if($5>45&&$5<90){print \"OK\"} else {print \"NG\" }}END{print \"The max tep is\",max}" 1.txt
```gawk "BEGIN{max=0}/CT/{if($5>max)max=$5;if($5>45&&$5<90){print \"OK\"} else {print \"NG\" }}END{print \"The max tep is\",max}" 1.txt```
|
|
2007-5-12 17:25 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
EQU - 等于
NEQ - 不等于
LSS - 小于
LEQ - 小于或等于
GTR - 大于
GEQ - 大于或等于
cmd里输入if /?了解一下?
EQU - equals
NEQ - not equals
LSS - less than
LEQ - less than or equal to
GTR - greater than
GEQ - greater than or equal to
Check out "if /?" in cmd?
|
|
2007-5-12 17:30 |
|