![]() |
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-12 08:20 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » 30,000 files quick replacement |
| Printable Version 3,112 / 21 |
| Floor1 plp626 | Posted 2010-03-02 23:59 |
| 银牌会员 Posts 1,020 Credits 2,278 | |
|
Right now there are more than 300,000 htm files (and a small number of html files). A considerable portion of these files have been defaced with malware. It is found that the source files of these defaced html and htm files have the URL mm.aa88567.cn in the last line.
Now, we need to find those defaced web pages (whose last line contains the string "mm.aa88567.cn"), and then delete their last line. Tools to be used: commonly used tools in Windows, or external tools: perl, sed,... (those with a volume size not exceeding 1M are all acceptable). Now we need to find the tool with the fastest processing speed and its solution (code) sed (40K version 4.0.7) download: http://upload.cn-dos.net/img/1813.rar perl (369K version 5.005_03) download: http://upload.cn-dos.net/img/1814.rar The following is the bat code for generating test files: [ Last edited by plp626 on 2010-3-4 at 23:00 ] |
|
| Floor2 radem | Posted 2010-03-03 01:46 |
| 高级用户 Posts 383 Credits 691 | |
|
Do you want the WIN32 one?
Speed is unknown Attachments 20100303013116751.png (2.68 KiB) |
|
| Floor3 Pierre | Posted 2010-03-03 02:19 |
| 初级用户 Posts 19 Credits 30 | |
|
Try
for /f "delims=" %%i in ('dir /s /b *.html') do sed -i "${/mm\.aa88567\.cn/d}" "%%i" [ Last edited by Pierre on 2010-3-3 at 02:23 ] |
|
| Floor4 HAT | Posted 2010-03-03 04:36 |
| 版主 Posts 5,017 Credits 9,023 | |
|
```
sed -i "/mm\.aa88567\.cn/d" *.html ``` |
|
| Floor5 qq330878338 | Posted 2010-03-03 14:34 |
| 新手上路 Posts 7 Credits 13 | |
|
Just took a look, it's not simple. Can only help to give a thumbs up.
|
|
| Floor6 plp626 | Posted 2010-03-03 15:09 |
| 银牌会员 Posts 1,020 Credits 2,278 | |
|
The code on floor 4 should be relatively fast ---- compared to the 3-way, there are no frequent starts of sed
However: Generate a test file using the bat code on floor 1 in the test directory. Open cmd under the parent directory of test, and type sed -i "/mm\.aa88567\.cn/d" test\*.html After that, in less than a few seconds, an error that sed cannot read memory appears It seems that sed supports batch processing of at most 512 files, because when 511 temporary files are generated in the directory, this error dialog pops up I don't know why, continue to pay attention.... [ Last edited by plp626 on 2010-3-3 at 15:11 ] |
|
| Floor7 tachyon | Posted 2010-03-03 16:06 |
| 初级用户 Posts 32 Credits 33 | |
|
Directly using sed is the fastest. Don't use for loops, as for loops are the least efficient. Frequent opening and closing of sed processes also consumes a great deal of system resources. It's estimated that the CPU/memory will run out soon. Also, processing 300,000 files one by one won't be too fast, after all, it involves disk operations, unlike computational tasks done in memory.
|
|
| Floor8 tachyon | Posted 2010-03-03 16:10 |
| 初级用户 Posts 32 Credits 33 | |
Originally posted by plp626 at 2010-3-3 15:09: This still depends on the sed documentation. If there is a limit on the number of files edited simultaneously, then you can first divide all files into several directories by quantity through batch, and then perform sed processing on each directory in turn. |
|
| Floor9 sady2009 | Posted 2010-03-03 16:41 |
| 初级用户 Posts 60 Credits 58 | |
|
Nowadays, memory is very large. Install a ramdisk, move files to the ramdisk, and then use batch processing. The access speed of small files is extremely amazing. It is almost the same as executing in memory.
|
|
| Floor10 Pierre | Posted 2010-03-03 17:19 |
| 初级用户 Posts 19 Credits 30 | |
|
Directly using *.html, the files matched by the wildcard are all passed to sed as parameters for execution, so it cannot exceed a certain amount.
——If you use sed like this under the shell, the following will appear Such an error. Of course, it's not just for sed, but also for awk/grep, etc. If you want higher efficiency, you can split the list and send 500 at a time to sed for processing [ Last edited by Pierre on 2010-3-3 at 17:20 ] |
|
| Floor11 Pierre | Posted 2010-03-03 17:27 |
| 初级用户 Posts 19 Credits 30 | |
|
Alternatively, directly use Perl to handle it and let it loop through the processing. Unfortunately, I'm not very familiar with using it. I'll try to write a solution later...
|
|
| Floor12 plp626 | Posted 2010-03-03 20:42 |
| 银牌会员 Posts 1,020 Credits 2,278 | |
|
I don't know Perl very well either, and I really hope some expert can try using the Perl provided in the first floor.
Looking forward... |
|
| Floor13 freeants001 | Posted 2010-03-04 16:19 |
| 中级用户 Posts 244 Credits 330 From 湖北 | |
|
Post a self-used JS file replacement code, which has been modified according to the building owner's requirements.
|
|
| Floor14 freeants001 | Posted 2010-03-04 20:18 |
| 中级用户 Posts 244 Credits 330 From 湖北 | |
|
Another AHK script
|
|
| Floor15 plp626 | Posted 2010-03-04 21:23 |
| 银牌会员 Posts 1,020 Credits 2,278 | |
|
I tried the code on floor 13. The speed was really good at that time, but the file extensions were all uniformly changed to txt. Those web files, the indexed ones have the suffix html and the non-indexed ones have htm.
I don't understand JS. How to modify the code so that the file extensions remain unchanged? |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |