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-23 01:35
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Filter out unknown numbers and letters in the text View 4,027 Replies 17
Original Poster Posted 2007-04-28 06:13 ·  中国 北京 联通
新手上路
Credits 14
Posts 6
Joined 2007-04-28 05:47
19-year member
UID 86746
Gender Male
Status Offline
Please tell me how to filter out all unknown numbers and letters in a text file and save them to a new text. These numbers and letters are interspersed in the document. For example: Xi Xi Ha Ha 12 Dong Dong ajs, Thinking, Today 0D12
Floor 2 Posted 2007-04-28 06:47 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Is it to filter out letters and numbers, or to filter out Chinese characters? Please make the problem description more specific for everyone to read.
Floor 3 Posted 2007-04-28 06:52 ·  中国 北京 联通
新手上路
Credits 14
Posts 6
Joined 2007-04-28 05:47
19-year member
UID 86746
Gender Male
Status Offline
Maybe the description is not clear enough. It is to filter out all numbers and letters in the document and only leave Chinese characters.
Floor 4 Posted 2007-04-28 07:07 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Floor 5 Posted 2007-04-28 07:11 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
vkill commands, it's a bit troublesome with batch processing.
Floor 6 Posted 2007-04-28 07:47 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
sed "s/[0-9a-zA-Z]/ /g" life
Floor 7 Posted 2007-04-28 08:06 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
Simple ones can still be handled (not considering special characters, and the processing of many spaces is not very reasonable)

Using batch processing to handle, simple demonstration code:

@echo off
setlocal enabledelayedexpansion

for /f "delims=" %%i in (test.txt) do (
call :Check "%%i" OK
echo !OK!
)

pause>nul

:Check Process object Return result
set "str=%~1"
set str_=

for /l %%i in (0 1 1000) do (
set tm_str=!str:~%%i,1!
if "!tm_str!"=="" set %2=!str_! & goto :eof
if "!tm_str!"==" " set str_=!str_!!tm_str!
if !tm_str! GTR Z set str_=!str_!!tm_str!
)

Explanation: The content in test.txt is the text content to be processed
Process object, small text, and does not contain special characters (because special characters are not considered here)
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
mqw624 +1 2010-12-06 19:37
Floor 8 Posted 2007-04-28 08:20 ·  中国 新疆 乌鲁木齐 电信
高级用户
★★★
Autowalk
Credits 845
Posts 375
Joined 2007-03-03 01:58
19-year member
UID 80606
Gender Male
Status Offline
```
set fso=createobject("scripting.filesystemobject")
set txt=fso.opentextfile("11.txt")
gettxt=txt.readall
numtxt=len(gettxt)

for i=1 to numtxt
unite=mid(gettxt,i,1)
on error resume next
int(unite)
if err.number=0 then
gettxt=replace(gettxt,unite," ")
end if
if asc(unite)>=65 and asc(unite)<=122 then
if asc(unite)<91 or asc(unite)>96 then
gettxt=replace(gettxt,unite," ")
end if
end if

next
msgbox gettxt,,"Filter"
set newtxt=fso.createtextfile("22.txt")
newtxt.write gettxt
'VBS version!
'11.txt is the file to be filtered, please modify it yourself, 22.txt is the saved text, you can not change it.
```
Floor 9 Posted 2007-04-28 22:50 ·  中国 北京 联通
新手上路
Credits 14
Posts 6
Joined 2007-04-28 05:47
19-year member
UID 86746
Gender Male
Status Offline
Thanks to everyone for your help. The trouble is that there are many spaces in the text I need to process, and if numbers or letters are alone in a line, there will be problems after filtering.

Also, the prompt "ECHO is off" appears. What does this mean?
Please help everyone! Thank you!
Floor 10 Posted 2007-04-29 00:53 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
```
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in (test.txt) do (
set str=%%i
set "str=!str: =!"
for /l %%j in (0,1,9) do (
if not "!str!"=="" set str=!str:%%j=!
)
for %%k in (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) do (
if not "!str!"=="" set str=!str:%%k=!
)

if not "!str!"=="" (
>>New.txt echo !str!
) else (
echo.
)
)

notepad New.txt
```

[ Last edited by huzixuan on 2007-4-29 at 06:14 AM ]
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 11 Posted 2007-04-29 02:24 ·  中国 北京 联通
新手上路
Credits 14
Posts 6
Joined 2007-04-28 05:47
19-year member
UID 86746
Gender Male
Status Offline
The answer from the person above can solve the problem of numbers or letters being alone in a line, but there is still a problem if there are spaces between numbers or letters!

Also, can you answer the question about the "ECHO is off" issue? Thank you very much!
Floor 12 Posted 2007-04-29 03:46 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
The reason for the appearance of "ECHO is off" is that the value after the echo command is empty.
Floor 13 Posted 2007-04-29 06:15 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
First, replace all spaces in the variable, then replace numbers and letters in sequence, and finally read out the variable. The code on floor 10 has been modified.
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 14 Posted 2007-04-29 06:37 ·  中国 安徽 芜湖 电信
高级用户
★★
Credits 537
Posts 219
Joined 2006-10-31 21:08
19-year member
UID 69036
Gender Male
From 芜湖
Status Offline
I don't know which one is more efficient.

set fso = CreateObject("Scripting.FileSystemObject")
set rfile = fso.OpenTextFile("test.txt",1)
set wfile = fso.CreateTextFile("Wfile.txt")
str = rfile.readall
for k = 0 to 9
str = replace(str,k," ") ' Replace numbers 0 - 9 with empty
next
for i = 65 to 90
str = replace(str,chr(i)," ") ' Replace lowercase letters a-z with empty
next
FOR J = 97 TO 122
STR = REPLACE(STR,CHR(J)," ") ' Replace uppercase letters A-Z with empty
NEXT
wfile.write str
wfile.close
江湖远
碧空长
路茫茫

一个人漫无目的的奔跑,风,刺骨的冷....
Floor 15 Posted 2007-04-29 07:13 ·  中国 北京 联通
新手上路
Credits 14
Posts 6
Joined 2007-04-28 05:47
19-year member
UID 86746
Gender Male
Status Offline
Thanks to huzixuan, I just solved the problem based on your original code, which is the same as your idea!

Also, thank you to everyone else for your help. I just started to get in touch with batch processing these days, but I really learned a lot here. Thank you all!

And another question, what does "echo." stand for?
Forum Jump: