![]() |
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-09-29 18:11 |
47,813 topics / 349,918 posts / today 0 new / 48,278 members |
| DOS批处理 & 脚本技术(批处理室) » How to split a file by markers using batch processing |
| Printable Version 13,999 / 30 |
| Floor16 willsort | Posted 2005-12-09 15:25 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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. |
|
| Floor17 yhsean | Posted 2005-12-09 19:28 |
| 初级用户 Posts 26 Credits 90 | |
|
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
|
|
| Floor18 tigerpower | Posted 2005-12-09 20:34 |
| 中级用户 Posts 99 Credits 377 | |
|
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.
|
|
| Floor19 willsort | Posted 2005-12-11 21:58 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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. [ Last edited by willsort on 2005-12-11 at 22:11 ] |
|
| Floor20 无奈何 | Posted 2005-12-11 23:43 |
| 荣誉版主 Posts 356 Credits 1,338 | |
|
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. |
|
| Floor21 无奈何 | Posted 2005-12-12 14:19 |
| 荣誉版主 Posts 356 Credits 1,338 | |
|
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. |
|
| Floor22 tigerpower | Posted 2005-12-12 21:24 |
| 中级用户 Posts 99 Credits 377 | |
Originally posted by Nai Nai He at 2005-12-12 14:19: 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! |
|
| Floor23 无奈何 | Posted 2005-12-12 22:12 |
| 荣誉版主 Posts 356 Credits 1,338 | |
|
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.
|
|
| Floor24 tigerpower | Posted 2005-12-13 08:33 |
| 中级用户 Posts 99 Credits 377 | |
|
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 ![]() |
|
| Floor25 Climbing | Posted 2005-12-13 09:20 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
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.
|
|
| Floor26 yhsean | Posted 2005-12-21 12:54 |
| 初级用户 Posts 26 Credits 90 | |
Originally posted by Wú Nài Hé at 2005-12-8 13:16: 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 ] |
|
| Floor27 LiveOnLove | Posted 2005-12-21 14:43 |
| 中级用户 Posts 161 Credits 493 From ZHCN | |
|
A bit confusing. @_@
|
|
| Floor28 yhsean | Posted 2005-12-28 19:41 |
| 初级用户 Posts 26 Credits 90 | |
|
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!) |
|
| Floor29 vkill | Posted 2007-02-12 10:29 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
|
Using sed, in principle it's possible, just for this specific one
[ Last edited by vkill on 2007-2-12 at 10:42 AM ] |
|
| Floor30 jmz573515 | Posted 2007-02-12 11:11 |
| 银牌会员 Posts 464 Credits 1,212 | |
|
Post a VBS one, just for fun
[ Last edited by jmz573515 on 2007-2-11 at 10:35 PM ] |
|
| Prev 1 2 3 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |