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-07-07 12:06
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Seek a batch script to extract characters from a text file View 5,398 Replies 27
Original Poster Posted 2006-12-26 03:00 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
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 ]
QQ:419503077
Floor 2 Posted 2006-12-26 03:08 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
for /f %i in (a.txt) do echo %i|findstr /e /i ".htm"&&echo %i>b.txt
Floor 3 Posted 2006-12-26 03:15 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
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 ]
QQ:419503077
Floor 4 Posted 2006-12-26 03:29 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
```
@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)
)
```
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 5 Posted 2006-12-26 03:38 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
你试过没有?

(注:原句“你试过没有?”本身就是中文,按要求直接返回)
Floor 6 Posted 2006-12-26 03:39 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Ashamed! I thought the content of www.txt was what the LZ posted!
Take a look at the attachment, wow!
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 7 Posted 2006-12-26 03:41 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
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.
QQ:419503077
Floor 8 Posted 2006-12-26 03:42 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
The user used a single >. If it works, only the last one will be retained. You should use >>
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 9 Posted 2006-12-26 03:43 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Originally posted by tianzizhi at 2006-12-26 03:41:
Brother ccwan's also doesn't work. In zhang.txt, there's only one web page name: 200104174738.htm.
Please improve it again. Also, the ones separated by spaces in each line aren't fixed 5 variables. Some are 6, some are 5. Please use my original text...


No way?! I tried it. According to the content you posted in the first floor (not the attachment), there are 66 displayed!
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 10 Posted 2006-12-26 03:44 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
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
QQ:419503077
Floor 11 Posted 2006-12-26 03:45 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
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 ]
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 12 Posted 2006-12-26 03:49 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
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?
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 13 Posted 2006-12-26 04:06 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
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..
QQ:419503077
Floor 14 Posted 2006-12-26 05:05 ·  中国 甘肃 兰州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Using third-party tools can solve it very well, heh heh, sed
Floor 15 Posted 2006-12-26 05:11 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Still, please ask vkill to write the code. I'll ask for advice on how to use sed when I have time.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Forum Jump: