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-08-09 20:02
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Experts, please help optimize the code View 2,835 Replies 41
Floor 31 Posted 2008-09-16 21:05 ·  中国 湖北 武汉 联通
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
If you have the file named your_file, remove the single quotes before your_file in this command.
Floor 32 Posted 2008-09-16 21:13 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
```gawk "{for (i=1;i<=NF;i++) { if($i~/^5-/){ split($i,a,/-/); if(a>max) max=a; }}} END{print max}" "a.txt"
```
Floor 33 Posted 2008-09-16 21:39 ·  中国 江苏 苏州 太仓市 电信
中级用户
★★
Credits 209
Posts 100
Joined 2008-08-01 02:53
18-year member
UID 122532
Gender Male
Status Offline
It works. Can you mark the meaning? So that I can learn to modify it by myself, especially the displayed part.

[ Last edited by dragonamd on 2008-9-16 at 09:40 PM ]
Floor 34 Posted 2008-09-16 21:44 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
print max
The "displayed part" is here, printing the value of max, marking the end.

ps. I don't know if the moderator feels a bit at a loss.
Floor 35 Posted 2008-09-16 21:49 ·  中国 江苏 苏州 太仓市 电信
中级用户
★★
Credits 209
Posts 100
Joined 2008-08-01 02:53
18-year member
UID 122532
Gender Male
Status Offline
Brother HAT, I'm really a newbie, but I'm trying to learn. Do you have to make fun of newbies like this? At least I've learned a lot in terms of P processing. Anyway, I should thank you all. The line break in the "print max" part makes it not display. Because I want to put the mark somewhere else.
Floor 36 Posted 2008-09-16 21:58 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
This, I have no intention of laughing at anyone, and I caused unnecessary misunderstandings. Sorry.

What I mean is that the moderator has answered very clearly, asking you to change your_file to your own file name. It is suggested to look back at the moderator's answer.

//print max I can't display it after changing lines. Because I want to put the mark elsewhere
I'm very stupid and don't understand what it means. Can you post the modified code you have to take a look?
Floor 37 Posted 2008-09-16 22:04 ·  中国 江苏 苏州 太仓市 电信
中级用户
★★
Credits 209
Posts 100
Joined 2008-08-01 02:53
18-year member
UID 122532
Gender Male
Status Offline
gawk "{for (i=1;i<=NF;i++) { if($i~/^5-/){ split($i,a,/-/); if(a>max) max=a; }}} END{print max}" "a.txt"
@echo %NewFile% %ste%  %sty% %max% I want to display many variables together
[ Last edited by dragonamd on 2008-9-17 at 12:43 AM ]
Floor 38 Posted 2008-09-17 00:44 ·  中国 江苏 苏州 太仓市 电信
中级用户
★★
Credits 209
Posts 100
Joined 2008-08-01 02:53
18-year member
UID 122532
Gender Male
Status Offline
Can you help me? I really don't understand this. I just looked at a lot of online tutorials, and none of them mentioned this part.
Floor 39 Posted 2008-09-17 07:48 ·  中国 湖北 武汉 联通
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Try this way

gawk "{for (i=1;i<=NF;i++) { if($i~/^5-/){ split($i,a,/-/); if(a>max) max=a; }}} END{print max}" "a.txt" > %temp%\tmp.p
set /p max=<%temp%\tmp.p
echo max 的值为 .
Floor 40 Posted 2008-09-17 09:28 ·  中国 江苏 苏州 太仓市 电信
中级用户
★★
Credits 209
Posts 100
Joined 2008-08-01 02:53
18-year member
UID 122532
Gender Male
Status Offline
Is the moderator's method to write the value to a temporary one and then read it?
Floor 41 Posted 2008-09-17 18:42 ·  中国 湖北 武汉 联通
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Originally posted by dragonamd at 2008-9-17 09:28:
Is the moderator's method to write the value to a temporary and then read it?

Hmm, is there any problem?
Floor 42 Posted 2008-09-17 20:49 ·  中国 江苏 苏州 太仓市 电信
中级用户
★★
Credits 209
Posts 100
Joined 2008-08-01 02:53
18-year member
UID 122532
Gender Male
Status Offline
No problem. I also thought about it last night, but I couldn't write it. The efficiency is very high, and I will study hard.
Forum Jump: