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 09:32
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Seek a batch script to extract characters from a text file View 5,395 Replies 27
Floor 16 Posted 2006-12-26 06:12 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
I tried it. The content in the www.txt file is just one line without line breaks. No wonder many of my attempts were incorrect. I made a small segment of the file and after pressing enter, the code of ccwan works, but there is a little error.
If there is no enter, just such a long single line, is there a way to extract it with a.htm ending? It's okay to use third-party tools. Everyone can think about how to do it when free, hehe.......
QQ:419503077
Floor 17 Posted 2006-12-26 06:27 ·  中国 甘肃 兰州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
sed "s/htm/\n/" life|sed "/.htm/!d"|sed "s/.* 200/200/;s/.htm.*/.htm/"|more>a.txt
type a.txt
pause>nul

[ Last edited by vkill on 2006-12-26 at 06:35 AM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +5 2006-12-26 21:49
Floor 18 Posted 2006-12-26 06:30 ·  中国 甘肃 兰州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Hehe, sed and awk are very easy for handling text
Floor 19 Posted 2006-12-26 06:54 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Didn't understand.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 20 Posted 2006-12-26 10:21 ·  中国 辽宁 本溪 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
After searching for a long time, I didn't find the pattern of the files.
Floor 21 Posted 2006-12-26 21:17 ·  中国 辽宁 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
Finally found the solution. Save the following code as a VBS.

The file you want to process www.txt and this VBS file must be in the same directory.


on error resume next
set fso=createobject("scripting.filesystemobject")
set file=fso.opentextfile("www.txt",1)
a=file.readall
file.close
i=0
do
i=instr(i+1,a,".htm")
if i<>0 then b=b & mid(a,i-12,16)& vbcrlf
loop until i=0
set file=fso.createtextfile("222.txt")
file.write b
file.close
msgbox "File processing completed, please check the 222.txt file",48+4096,"Operation successful"


[ Last edited by jmz573515 on 2006-12-26 at 08:44 AM ]
Recent Ratings for This Post ( 3 in total) Click for details
RaterScoreTime
namejm +4 2006-12-26 21:44
tianzizhi +4 2006-12-26 23:10
lxmxn +4 2006-12-27 02:14
Floor 22 Posted 2006-12-26 21:31 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
According to your prompt, I put www.txt and that vbs in the same directory for operation, but it still went wrong.
Attachments
出错.JPG
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 23 Posted 2006-12-26 21:36 ·  中国 辽宁 联通
银牌会员
★★★
Credits 1,212
Posts 464
Joined 2006-12-13 21:11
19-year member
UID 73417
Gender Male
Status Offline
Oh, dizziness~~
I've tried many times and there's no problem. Is the file name you need to handle www.txt?

If it still doesn't work, you can try changing www.txt to 11.txt and then also change www.txt in the vbs to 11.txt to see if it works.
Floor 24 Posted 2006-12-26 21:42 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Made a rookie mistake: when copying the code, I missed the initial '. It is suggested to enclose the code part with [code] and [/code] to facilitate others' copying.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 25 Posted 2006-12-26 23:13 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
VBS is indeed powerful, but I can't learn it right now. I still need to study my C. I'll try to use C to solve the problems I encounter in the future.
QQ:419503077
Floor 26 Posted 2009-04-12 08:55 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
```
@echo off&setlocal enabledelayedexpansion
set "t="
(for /f "tokens=*" %%a in (www.txt) do (set "str=!t!%%a"&set "t=%%a"&call :sub !str!))>dest.txt
start dest.txt
pause
goto :eof
:sub
if /i "%~x1"==".htm" echo %1
shift
if not "%1"=="" goto :sub
set t=!t:.htm=!
goto :eof
```

A purely batch one!
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
asnahu +2 2009-06-23 13:04
精简
=> 个人网志
Floor 27 Posted 2009-04-12 09:20 ·  中国 湖北 黄石 阳新县 电信
中级用户
★★
Credits 330
Posts 244
Joined 2006-04-14 14:07
20-year member
UID 53823
Gender Male
From 湖北
Status Offline
Why can't I download the attachment!~~~
Floor 28 Posted 2009-04-12 09:50 ·  中国 湖北 黄石 阳新县 电信
中级用户
★★
Credits 330
Posts 244
Joined 2006-04-14 14:07
20-year member
UID 53823
Gender Male
From 湖北
Status Offline
A hybrid one
more +4 "%~f0">#js.js
cscript /nologo #js.js 文件.txt
goto:eof
:::::::::::::::::::::::
File_Path=WScript.arguments(0);
var fso=new ActiveXObject("scripting.filesystemobject");
var fl=fso.opentextfile(File_Path,1);
var sss=fl.readall();
var fl=fso.opentextfile(File_Path+"_处理后.txt",2,1);
sss=sss.replace(/*?\s+(\d+\.htm)/g,"$1\r\n");
fl.write(sss);
Forum Jump: