![]() |
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-26 01:19 |
47,812 topics / 349,910 posts / today 0 new / 48,264 members |
| DOS批处理 & 脚本技术(批处理室) » Seek a batch script to extract characters from a text file |
| Printable Version 5,654 / 27 |
| Floor1 tianzizhi | Posted 2006-12-26 03:00 |
| 高级用户 Posts 214 Credits 623 | |
|
Now the content of the www.txt file is as follows. I want to use a batch processing to extract the web page names ending with.htm from www.txt, such as:
200104174738.htm 200104174772.htm 200104174786.htm Then put them into the zhang.txt file. How to achieve this? Thank you. Do not use third-party tools. The original file is here: www.txt 2002-01-23 3:26 6031 200104174738.htm 2002-01-23 3:26 5553 200104174772.htm 2002-01-23 3:26 5155 200104174773.htm 2002-01-23 3:26 7634 200104174781.htm 2002-01 23 3:26 5180 200104174786.htm 2002-01-23 3:26 6658 200104174834.htm 2002-01-23 3:26 6351 200104174883.htm 2002-01-23 3:26 4249 200104174897.htm 2002-01-23 3:26 4207 200104174907.htm 2002-01-23 3:26 7199 200104174931.htm 2002-01-23 3:26 6346 200104174932.htm 2002-01 23 3:26 8475 200104174943.htm 2002-01-23 3:26 5321 200104174954.htm 2002-01-23 3:26 5831 200104174977.htm 2002-01-23 3:26 6150 200104174978.htm 2002-01-23 3:26 10850 200104175018.htm 2002-01-23 3:26 7552 200104175037.htm 2002-01-23 3:26 7879 200104175047.htm 2002-01 23 3:26 5086 200104175054.htm 2002-01-23 3:26 6753 200104175055.htm 2002-01-23 3:26 3925 200104175079.htm 2002-01-23 3:26 5588 200104175081.htm 2002-01-23 3:26 5237 200104175082.htm 2002-01-23 3:26 5881 200104175130.htm 2002-01-23 3:26 5047 200104175170.htm 2002-01 23 3:26 5423 200104175225.htm 2002-01-23 3:26 6273 200104175226.htm 2002-01-23 3:26 8096 200104175235.htm 2002-01-23 3:26 5479 200104175256.htm 2002-01-23 3:26 6392 200104175257.htm 2002-01-23 3:26 10924 200104175258.htm 2002-01-23 3:26 5758 200104175259.htm 2002-01 23 3:26 6058 200104175276.htm 2002-01-23 3:26 3535 200104175288.htm 2002-01-23 3:26 5297 200104175333.htm 2002-01-23 3:26 6738 200104175361.htm 2002-01-23 3:26 8533 200104175366.htm 2002-01-23 3:26 7232 200104175370.htm 2002-01-23 3:26 6548 200104175382.htm 2002-01 23 3:26 7091 200104175391.htm 2002-01-23 3:26 4415 200104175400.htm 2002-01-23 3:26 5165 200104175411.htm 2002-01-23 3:26 7801 200104175412.htm 2002-01-23 3:26 3750 200104175431.htm 2002-01-23 3:26 4553 200104175432.htm 2002-01-23 3:26 7356 200104175457.htm 2002-01 23 3:26 5534 200104175488.htm 2002-01-23 3:26 5488 200104175506.htm 2002-01-23 3:26 8817 200104175516.htm 2002-01-23 3:26 5239 200104175573.htm 2002-01-23 3:26 8497 200104175634.htm 2002-01-23 3:26 12113 200104175653.htm 2002-01-23 3:26 5094 200104175661.htm 2002-01 23 3:26 8138 200104175690.htm 2002-01-23 3:26 4387 200104175707.htm 2002-01-23 3:26 3770 200104175732.htm 2002-01-23 3:26 5334 200104175733.htm 2002-01-23 3:26 6303 200104175744.htm 2002-01-23 3:26 7621 200104175745.htm 2002-01-23 3:26 5329 200104175746.htm 2002-01 23 3:26 6310 200104175789.htm 2002-01-23 3:26 4983 200104175808.htm 2002-01-23 3:26 6183 200104175815.htm 2002-01-23 3:26 6465 200104175835.htm 2002-01-23 3:26 6460 200104175849.htm 2002-01-23 3:26 7387 200104175858.htm 2002-01-23 3:26 6035 200104175862.htm 2002-01 23 3:26 5212 200104175872.htm 2002-01-23 3:26 7749 200104175897.htm 2002-01-23 3:26 8160 200104175910.htm 2002-01-23 3:26 4545 200104175933.htm 2002-01-23 3:26 5628 200104175934.htm 2002-01-23 3:26 3817 200104175981.htm 2002-01-23 3:26 3085 200104175982.htm 2002-01 23 3:26 8211 200104175983.htm 2002-01-23 3:26 5113 200104176007.htm 2002-01-23 3:26 4888 200104176012.htm [ Last edited by tianzizhi on 2006-12-26 at 03:02 AM ] |
|
| Floor2 everest79 | Posted 2006-12-26 03:08 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
|
for /f %i in (a.txt) do echo %i|findstr /e /i ".htm"&&echo %i>b.txt
|
|
| Floor3 tianzizhi | Posted 2006-12-26 03:15 |
| 高级用户 Posts 214 Credits 623 | |
|
The person upstairs shouldn't be arbitrary, it has to be tested personally. If it were that easy, I wouldn't post the thread. What you wrote will only get the first variable and that's it. But the first variable isn't the web page name ending with.htm that I want. But still thank you for your enthusiastic help.
[ Last edited by tianzizhi on 2006-12-26 at 03:16 AM ] |
|
| Floor4 ccwan | Posted 2006-12-26 03:29 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
|
```
@echo off for /f "tokens=1-5 delims= " %%i in (www.txt) do ( if ".htm"=="%%~xi" (>>zhang.txt echo %%i) if ".htm"=="%%~xj" (>>zhang.txt echo %%j) if ".htm"=="%%~xk" (>>zhang.txt echo %%k) if ".htm"=="%%~xl" (>>zhang.txt echo %%l) if ".htm"=="%%~xm" (>>zhang.txt echo %%m) ) ``` |
|
| Floor5 everest79 | Posted 2006-12-26 03:38 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
|
你试过没有?
(注:原句“你试过没有?”本身就是中文,按要求直接返回) |
|
| Floor6 ccwan | Posted 2006-12-26 03:39 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
|
Ashamed! I thought the content of www.txt was what the LZ posted!
Take a look at the attachment, wow! |
|
| Floor7 tianzizhi | Posted 2006-12-26 03:41 |
| 高级用户 Posts 214 Credits 623 | |
|
Brother ccwan's doesn't work either. In zhang.txt, there's only one web page name: 200104174738.htm. Please improve it further. Also, the lines are separated by spaces, and it's not fixed with 5 variables. Some have 6, some have 5. Please test with my original file.
|
|
| Floor8 ccwan | Posted 2006-12-26 03:42 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
|
The user used a single >. If it works, only the last one will be retained. You should use >>
|
|
| Floor9 ccwan | Posted 2006-12-26 03:43 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
Originally posted by tianzizhi at 2006-12-26 03:41: No way?! I tried it. According to the content you posted in the first floor (not the attachment), there are 66 displayed! |
|
| Floor10 tianzizhi | Posted 2006-12-26 03:44 |
| 高级用户 Posts 214 Credits 623 | |
|
Reply to everest79, I tried what you did, and only got: January 23, 2002, that.
You analyze your written line again: for /f %i in (a.txt) do echo %i|findstr /e /i ".htm"&&echo %i>b.txt |
|
| Floor11 ccwan | Posted 2006-12-26 03:45 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
|
Also, the content of your attachment doesn't wrap lines. It's strange. Can't read it correctly.
[ Last edited by ccwan on 2006-12-26 at 03:48 AM ] |
|
| Floor12 namejm | Posted 2006-12-26 03:49 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
www.txt There may be no carriage returns in the text, causing the for statement to be unable to handle such long line content. Can the owner post a text with carriage returns?
|
|
| Floor13 tianzizhi | Posted 2006-12-26 04:06 |
| 高级用户 Posts 214 Credits 623 | |
|
Could it really be because of no carriage return? (This error is not easy to find), I saved the web page as .txt to get www.txt. If using carriage return can solve this problem, then the problem will be considered solved. Thank you everyone, hehe..
|
|
| Floor14 vkill | Posted 2006-12-26 05:05 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
|
Using third-party tools can solve it very well, heh heh, sed
|
|
| Floor15 ccwan | Posted 2006-12-26 05:11 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
|
Still, please ask vkill to write the code. I'll ask for advice on how to use sed when I have time.
|
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |