|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 16 楼』:
使用 LLM 解释/回答一下
Re All:
首先,发布一则启事:
因本人的个人电脑现已搬至别处,与网络隔绝,以作封闭式训练之用,时间至少两周。此段时间内,只有闲暇时间可以在网吧或他人电脑处登录论坛,所以暂时恢复在线收发、离线阅复的上网习惯,因此必然会导致阅读频率降低、回复周期延长以及管理力度减弱,敬请管理层和广大朋友谅解!
tigerpower兄所言之情状,恰有以下三点感受,列述于下:以古语云,知其然而不知其所以然;用如今的观点讲,明白结果未必懂得过程;拿民间的俗话说,听过老虎会吃人的多,见过老虎咋吃人的少。
我于awk,算得上“鼎鼎大名,如雷贯耳;奈何天意弄人,缘悭一识”。这个源出于 Unix 家族的命令行工具,我在学习批处理的过程曾偶有涉猎,却总是未及深入。除却与无奈何兄相似的畏难避险的人之常情外,尚有一份维护批处理血统纯正的崖岸自高在内。但我亦深知,工具的价值,就是在适当的时间、适当的场合被适当的人所使用,一味逃避不过是掩耳盗铃的鸵鸟心态而已。现在,看到无奈何兄比我更早迈出了这一步,欣喜之余不免惭愧。
现已作决定,与其站在门外为看到热闹而喝彩,不如坐于阁内因识出三昧而击节——awk,是时候接触了。
Re All:
First of all, issue an announcement:
Because my personal computer has now been moved elsewhere, cut off from the network, for closed training, for at least two weeks. During this period, I can only log in to the forum in Internet cafes or on others' computers during spare time, so I will temporarily resume the online receiving and offline replying internet habits. Therefore, it will inevitably lead to reduced reading frequency, extended reply cycles, and weakened management efforts. Please understand from the management and friends!
Brother tigerpower's described situation, there are exactly the following three feelings, listed as follows: As the ancient saying goes, know that it is so but do not know why it is so; in today's view, understand the result but not necessarily understand the process; in the words of folk sayings, heard that tigers can eat people a lot, but saw how tigers eat people few.
I, regarding awk, can be regarded as "very famous, well-known; but fate plays tricks, missed meeting". This command-line tool originating from the Unix family, I have had occasional exposure during the process of learning batch processing, but always failed to go deep. In addition to the common human sentiment of fear of difficulties and avoiding risks similar to Brother Wunaike, there is also a self-importance of maintaining the pure lineage of batch processing. But I also deeply understand that the value of a tool is to be used by the right person at the right time and in the right place. Blindly avoiding is just the ostrich mentality of covering one's ears to steal a bell. Now, seeing that Brother Wunaike has taken the first step earlier than me, I am happy and a bit ashamed.
Now I have made a decision, instead of standing outside the door to cheer for seeing the excitement, it is better to sit inside the pavilion to clap for recognizing the essence - awk, it's time to get in touch.
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2005-12-9 15:25 |
|
|
yhsean
初级用户
 
积分 90
发帖 26
注册 2005-12-5
状态 离线
|
『第 17 楼』:
使用 LLM 解释/回答一下
得到各位的帮助。太感谢了。请二位推荐 UNIX最 常用的命令
学习之,以解决实际工作诸多问题
向前辈致敬
Got the help from everyone. Thank you so much. Please two of you recommend the most commonly used commands in UNIX for learning to solve many problems in actual work. Pay tribute to the seniors
|
|
2005-12-9 19:28 |
|
|
tigerpower
中级用户
   大师兄
积分 377
发帖 99
注册 2005-8-26
状态 离线
|
『第 18 楼』:
使用 LLM 解释/回答一下
原来如此,我还以为板主已经见到了偶上次用mawk的解法,呵呵.
本来是想看看各位如何用sed解题,所以就把那张贴给删了 
Oh, I see. I thought the forum moderator had already seen my previous solution using mawk. Actually, I deleted that post because I wanted to see how everyone would solve it with sed.
|
|
2005-12-9 20:34 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 19 楼』:
使用 LLM 解释/回答一下
Re tigerpower:
我未见到兄的 mawk 的解法,论坛本来就是百花齐放之地,所以还有兄不要藏珍才好。
今天下午,终于有空看了部分中文的 awk 文档,根据自己的初浅认识,仍然回应楼主最初的主题,编写了我的第一个 awk 脚本,因为与无奈何兄脚本尚有一些区别,所以贴上来,以抛砖引玉。
Re 无奈何:
注意到兄的 awk 脚本中是采用一个 temp 变量来做中转的,与print>>相比,字符串变量的连接后再整体输出有可能效率更高一些吗?不知道楼主是否还有心思做一下这方面的测试?因为在我这里不太容易找到规模较大的测试文件。
{
if ($1 !~ /^R\*/) {
print $0>>"temp"
} else {
close("temp")
system("ren temp "substr($0,3)".txt")
}
}
Last edited by willsort on 2005-12-11 at 22:11 ]
Re tigerpower:
I haven't seen your solution with mawk. The forum is supposed to be a place where various ideas flourish, so you shouldn't be too stingy with your insights.
This afternoon, I finally had time to read some Chinese awk documentation. Based on my initial understanding, I still responded to the original topic starter and wrote my first awk script. Since there are still some differences from Brother Wunaaihe's script, I'm posting it to start a discussion.
Re 无奈何:
I noticed that in your awk script, you use a temp variable as an intermediate. Compared with print>>, is there a possibility that concatenating string variables and then outputting them all at once is more efficient? I don't know if the topic starter still has the intention to do some testing in this regard? Because it's not easy for me to find a larger - scale test file here.
{
if ($1 !~ /^R\*/) {
print $0>>"temp"
} else {
close("temp")
system("ren temp "substr($0,3)".txt")
}
}
Last edited by willsort on 2005-12-11 at 22:11 ]
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2005-12-11 21:58 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 20 楼』:
使用 LLM 解释/回答一下
to yhsean
关于你想了解“UNIX常用的命令”,我在 7 楼已经提到一个工具包,你可以找来玩玩。
to willsort
兄的学习速度够快的!中间变量的使用肯定会降低效率的,但那时是现学现用的,还不知道close()函数,而直接调用system命令更改文件名又失败,没有办法下只能投机应对,但那是我的第一个 AWK 程序,不打算修改了。最好兄能将你完整的程序贴出来,给本帖问题作个完美的解答吧。
to yhsean
Regarding the "common commands in UNIX" you want to know, I mentioned a toolkit on floor 7. You can find it and play with it.
to willsort
Brother, your learning speed is quite fast! The use of intermediate variables will definitely reduce efficiency, but at that time, I was learning and using it on the spot. I didn't know the close() function, and directly calling the system command to change the file name failed. There was no way, so I had to take a shortcut. But that was my first AWK program, and I don't plan to modify it. It would be best if you can post your complete program to give a perfect solution to this thread's problem.
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2005-12-11 23:43 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 21 楼』:
使用 LLM 解释/回答一下
to tigerpower
mawk 的速度和稳定性是很出众的,可遗憾的是资料太少了。
你的代码 gawk 不能通过,我觉得你的这段代码应该是通用的,结果换了低版本的 gawk 通过了,让我狂晕。
to tigerpower
The speed and stability of mawk are quite remarkable, but unfortunately there are very few materials.
Your code in gawk doesn't pass. I thought your code should be universal, but it passed with a lower version of gawk, which makes me extremely confused.
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2005-12-12 14:19 |
|
|
tigerpower
中级用户
   大师兄
积分 377
发帖 99
注册 2005-8-26
状态 离线
|
『第 22 楼』:
使用 LLM 解释/回答一下
Originally posted by 无奈何 at 2005-12-12 14:19:
...结果换了低版本的 gawk 通过了,让我狂晕
哈哈,gawk我到是没试过。
GNU utilities for Win32这个东东我也用,不过其中的join有bug,兄弟们用起来要当心啊!
Originally posted by Nai Nai He at 2005-12-12 14:19:
...As a result, switching to a lower version of gawk worked, which really made me dizzy
Haha, I haven't tried gawk yet.
I also use GNU utilities for Win32, but the join in it has a bug, so brothers should be careful when using it!
|
|
2005-12-12 21:24 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 23 楼』:
使用 LLM 解释/回答一下
较新版本的 GAWK 我再也不敢用了,稳定性太差了。今天练习了一段程序,较新的几版 GAWK 居然得到匪夷所思的结果,而旧版和其它版的 AWK 完全正常。同样的脚本得到不同的结果,这比无法运行通过要严重的多,太难以让人接受了。
I no longer dare to use the newer versions of GAWK because of their poor stability. Today, while practicing a program, I got bizarre results with the newer versions of GAWK, but the older versions and other versions of AWK worked perfectly. Getting different results with the same script is much more serious than not being able to run through, and it's too hard to accept.
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2005-12-12 22:12 |
|
|
tigerpower
中级用户
   大师兄
积分 377
发帖 99
注册 2005-8-26
状态 离线
|
『第 24 楼』:
使用 LLM 解释/回答一下
GNU的旗舰产品是gcc和emacs, 其他软件的代码质量和运行性能值得商榷.
但是在大部分Linux论坛里把Linux和GNU吹得天花乱坠,主观色彩太浓烈了.
平时我也用Linux, 有很多软件我觉得BSD版本的更为优秀 
The flagship products of GNU are gcc and emacs, and the code quality and running performance of other software are open to question.
But in most Linux forums, Linux and GNU are hyped up to the skies, with too strong a subjective color.
I also use Linux in daily life. I think the BSD versions of many software are better:cool:
|
|
2005-12-13 08:33 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 25 楼』:
使用 LLM 解释/回答一下
看完这个帖子良久,我的大脑仍然是一片晕。Unix的东西实在搞得太复杂,非我这种简单的大脑可以理解的。
After reading this post for a long time, my brain is still in a muddle. Unix - related things are really too complicated, not something that my simple brain can understand.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2005-12-13 09:20 |
|
|
yhsean
初级用户
 
积分 90
发帖 26
注册 2005-12-5
状态 离线
|
『第 26 楼』:
使用 LLM 解释/回答一下
Originally posted by 无奈何 at 2005-12-8 13:16:
BEGIN { FS="\n"}
{
if ($1~/^R.*/) {
name = substr($1,length($1)-1)
temp = substr(temp,2)
print temp>name".txt"
temp = ""
}
else {
temp = (temp "\n" $1)
}
}
再次消化 无奈何兄脚本 发现可以这样使其简洁点
$0~/^R.*/? { print temp>substr($1,3)".txt"; temp = "" } : temp = (temp $0 )
Last edited by yhsean on 2005-12-22 at 13:29 ]
Originally posted by Wú Nài Hé at 2005-12-8 13:16:
BEGIN { FS="\n"}
{
if ($1~/^R.*/) {
name = substr($1,length($1)-1)
temp = substr(temp,2)
print temp>name".txt"
temp = ""
}
else {
temp = (temp "\n" $1)
}
}
Re-digest Brother Wú Nài Hé's script and find that it can be made more concise like this
$0~/^R.*/? { print temp>substr($1,3)".txt"; temp = "" } : temp = (temp $0 )
Last edited by yhsean on 2005-12-22 at 13:29 ]
|
|
2005-12-21 12:54 |
|
|
LiveOnLove
中级用户
  
积分 493
发帖 161
注册 2002-10-29 来自 ZHCN
状态 离线
|
|
2005-12-21 14:43 |
|
|
yhsean
初级用户
 
积分 90
发帖 26
注册 2005-12-5
状态 离线
|
『第 28 楼』:
使用 LLM 解释/回答一下
不好意思,技术是严谨的,纠正我上次的一个错误
{
if ($1 !~ /^R\*/) {
print $0>>"temp"
} else {
close("temp")
system("ren temp "substr($0,3)".txt")
}
}
代码输出比用变量中转一次性输出快,我想应该这样去理解
不用中转变量,处理完就会释放内存中的信息,用中转变量的话,如果中转变量的容量过大的话,速度,直线下降,这在测试一个10M文本内容的出的结果
特此更正,以免误导人!
I'm sorry, technology is precise. Correcting an error from my last time
{
if ($1 !~ /^R\*/) {
print $0>>"temp"
} else {
close("temp")
system("ren temp "substr($0,3)".txt")
}
}
The code output is faster than using a variable to buffer and output all at once. I think it should be understood like this:
Without using a buffer variable, once processed, the information in memory is released. If a buffer variable is used, if the capacity of the buffer variable is too large, the speed drops sharply. This was the result from testing a 10M text content.
特此更正,以免误导人!(Here is the correction to avoid misleading others!)
|
|
2005-12-28 19:41 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 29 楼』:
使用 LLM 解释/回答一下
用sed的,原理上可以的,只是针对这个专门的
@echo off
set life=AA.txt
for /l %%? in (2,1,100) do (
call :test "%%?"
)
exit
:test
set/a var1=%~1-1
set/a var2=%~1-2
type %life%|findstr "^R\**%var1%$" >nul||(goto end)
if defined a (sed "/^R\**%var2%$/,/^R\**%var1%$/!d" %life% |sed "1d;$d"|more>%var1%.txt
) else (
set a=a
sed "1,/^R\**%var1%$/!d" %life% |sed "$d" |more>%var1%.txt
)
goto :eof
:end
sed "/^R\**%var2%$/,$!d" %life% |sed "1d"|more>n.txt
exit
goto :eof
Last edited by vkill on 2007-2-12 at 10:42 AM ]
Using sed, in principle it's possible, just for this specific one
@echo off
set life=AA.txt
for /l %%? in (2,1,100) do (
call :test "%%?"
)
exit
:test
set/a var1=%~1-1
set/a var2=%~1-2
type %life%|findstr "^R\**%var1%$" >nul||(goto end)
if defined a (sed "/^R\**%var2%$/,/^R\**%var1%$/!d" %life% |sed "1d;$d"|more>%var1%.txt
) else (
set a=a
sed "1,/^R\**%var1%$/!d" %life% |sed "$d" |more>%var1%.txt
)
goto :eof
:end
sed "/^R\**%var2%$/,$!d" %life% |sed "1d"|more>n.txt
exit
goto :eof
Last edited by vkill on 2007-2-12 at 10:42 AM ]
|
|
2007-2-12 10:29 |
|
|
jmz573515
银牌会员
    
积分 1212
发帖 464
注册 2006-12-13
状态 离线
|
『第 30 楼』:
使用 LLM 解释/回答一下
发一个VBS的,揍个热闹
on error resume next
set fso=createobject("scripting.filesystemobject")
set d=createobject("scripting.dictionary")
set file=fso.opentextfile("a.txt")
do while file.atendofstream<>true
m=m+1
d.add m,file.readline
loop
file.close
a=d.items
for i=0 to m-1
if left(a(i),2)<>"R*" then
s=s&a(i)&vbcrlf
h=mid(a(i+1),3)
else
set file=fso.createtextfile(h & ".txt")
file.write s
file.close
s=""
end if
next
msgbox "按标记“R*”分割文件成功。",4096,"系统提示"
Last edited by jmz573515 on 2007-2-11 at 10:35 PM ]
Post a VBS one, just for fun
on error resume next
set fso=createobject("scripting.filesystemobject")
set d=createobject("scripting.dictionary")
set file=fso.opentextfile("a.txt")
do while file.atendofstream<>true
m=m+1
d.add m,file.readline
loop
file.close
a=d.items
for i=0 to m-1
if left(a(i),2)<>"R*" then
s=s&a(i)&vbcrlf
h=mid(a(i+1),3)
else
set file=fso.createtextfile(h & ".txt")
file.write s
file.close
s=""
end if
next
msgbox "Successfully split the file by the mark 'R*'.",4096,"System Prompt"
Last edited by jmz573515 on 2007-2-11 at 10:35 PM ]
|
|
2007-2-12 11:11 |
|
|