中国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-08-09 21:02
47,811 topics / 349,897 posts / today 2 new / 48,255 members
DOS批处理 & 脚本技术(批处理室) » Experts, please help optimize the code
Printable Version  2,843 / 41
Floor1 dragonamd Posted 2008-09-12 04:51
中级用户 Posts 100 Credits 209
R02 u70.843 i-19.91 5-10.17 I5.641
U71.796 B-18.487 5-8.11 I4.556
G75.13 H-10.666 5-9.16 I-9.209
F75.13 5-7.27 H-10.666 I-9.209

Among the above, the number after 5- is 10.17 which is the largest, so display 5-10.17


@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in (a.txt) do (
for %%i in (%%a) do (
set "var=%%i"
if "!var:~,1!" equ "5" (
set "var= !var!"
set "_!var:~-10!=%%i"
)
)
)
for /f "tokens=2 delims==" %%i in ('set _') do set "max=%%i"
echo %max%
pause

The code works. However, if it's executed on a 10MB text, the execution efficiency is extremely slow, taking almost half an hour. VBS is also okay, as long as it's faster.

[ Last edited by dragonamd on 2008-9-12 at 05:10 AM ]
Floor2 bat-zw Posted 2008-09-12 11:16
金牌会员 Posts 1,276 Credits 3,105
The efficiency problem of the code lies in set _. The modification is as follows:
Floor3 bat-zw Posted 2008-09-12 11:39
金牌会员 Posts 1,276 Credits 3,105
```
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in (a.txt) do (
for %%b in (%%a) do (
set "var=%%b"
if "!var:~,2!" equ "5-" (
if not defined max set "max=!var:~2!"
for /f "tokens=1* delims=." %%c in ("!max!") do set "max1=%%c"&set "max2=%%d"
for /f "tokens=1* delims=." %%e in ("!var:~2!") do (
if %%e gtr !max1! (
set "max=!var:~2!"
) else (
if %%e equ !max1! if %%d gtr !max2! set "max=!var:~2!"
         )
)
)
)
)
echo %max%&pause>nul
```
Floor4 huahua0919 Posted 2008-09-12 12:54
银牌会员 Posts 780 Credits 1,608
Borrow the S11S1 code to write a VBS


[ Last edited by huahua0919 on 2008-9-12 at 01:06 PM ]
Floor5 dragonamd Posted 2008-09-12 15:27
中级用户 Posts 100 Credits 209
The code has all been tested. Still, it doesn't speed up. The 10MB text is still as slow.
Floor6 lxmxn Posted 2008-09-12 15:58
版主 Posts 4,938 Credits 11,386
Try with gawk...
Floor7 dragonamd Posted 2008-09-13 02:37
中级用户 Posts 100 Credits 209
Floor8 lxmxn Posted 2008-09-13 12:07
版主 Posts 4,938 Credits 11,386
Originally posted by dragonamd at 2008-9-13 02:37:
Can't write,

You can learn by yourself if you can't write.


[ Last edited by lxmxn on 2008-9-13 at 12:09 PM ]
Floor9 dragonamd Posted 2008-09-13 12:17
中级用户 Posts 100 Credits 209
It doesn't work after running. I really don't understand.
Floor10 lxmxn Posted 2008-09-13 12:26
版主 Posts 4,938 Credits 11,386
gawk is a tool that needs to be downloaded. Just search online.

It runs normally here.

ps It is suggested to take a look at the top-sticked batch processing novice FAQ.
Floor11 dragonamd Posted 2008-09-14 00:07
中级用户 Posts 100 Credits 209
Floor12 HAT Posted 2008-09-14 02:18
版主 Posts 5,017 Credits 9,023
It can be batch processed, but according to your requirements, the efficiency of batch processing is not as high as that of gawk.
Floor13 dragonamd Posted 2008-09-14 19:48
中级用户 Posts 100 Credits 209
I don't know how to install and use that tool
Floor14 HAT Posted 2008-09-14 19:50
版主 Posts 5,017 Credits 9,023
No need to install, just download gawk.exe and you can call it directly in batch processing. If you don't know how to use it, you can view the help.
Floor15 dragonamd Posted 2008-09-14 21:23
中级用户 Posts 100 Credits 209
I've been searching online for a long time and can't download it. Can you provide a download?
1 2 3  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023