中国DOS联盟论坛

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-10-24 04:10
47,815 topics / 349,928 posts / today 1 new / 48,287 members
DOS批处理 & 脚本技术(批处理室) » Seek a batch script to extract characters from a text file
Printable Version  6,137 / 27
Floor16 tianzizhi Posted 2006-12-26 06:12
高级用户 Posts 214 Credits 623
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.......
Floor17 vkill Posted 2006-12-26 06:27
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
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 ]
Floor18 vkill Posted 2006-12-26 06:30
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Hehe, sed and awk are very easy for handling text
Floor19 ccwan Posted 2006-12-26 06:54
金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊
Didn't understand.
Floor20 jmz573515 Posted 2006-12-26 10:21
银牌会员 Posts 464 Credits 1,212
After searching for a long time, I didn't find the pattern of the files.
Floor21 jmz573515 Posted 2006-12-26 21:17
银牌会员 Posts 464 Credits 1,212
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.



[ Last edited by jmz573515 on 2006-12-26 at 08:44 AM ]
Floor22 namejm Posted 2006-12-26 21:31
荣誉版主 Posts 1,737 Credits 5,226 From 成都
According to your prompt, I put www.txt and that vbs in the same directory for operation, but it still went wrong.

Attachments
出错.JPG (9.48 KiB)
Floor23 jmz573515 Posted 2006-12-26 21:36
银牌会员 Posts 464 Credits 1,212
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.
Floor24 namejm Posted 2006-12-26 21:42
荣誉版主 Posts 1,737 Credits 5,226 From 成都
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.
Floor25 tianzizhi Posted 2006-12-26 23:13
高级用户 Posts 214 Credits 623
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.
Floor26 netbenton Posted 2009-04-12 08:55
银牌会员 Posts 752 Credits 1,916 From 广西
```
@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!
Floor27 freeants001 Posted 2009-04-12 09:20
中级用户 Posts 244 Credits 330 From 湖北
Why can't I download the attachment!~~~
Floor28 freeants001 Posted 2009-04-12 09:50
中级用户 Posts 244 Credits 330 From 湖北
A hybrid one
Prev  1 2
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023