![]() |
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-09-14 17:22 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS批处理 & 脚本技术(批处理室) » Filter out unknown numbers and letters in the text |
| Printable Version 4,503 / 17 |
| Floor1 xixi27 | Posted 2007-04-28 06:13 |
| 新手上路 Posts 6 Credits 14 | |
|
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
|
|
| Floor2 lxmxn | Posted 2007-04-28 06:47 |
| 版主 Posts 4,938 Credits 11,386 | |
|
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.
|
|
| Floor3 xixi27 | Posted 2007-04-28 06:52 |
| 新手上路 Posts 6 Credits 14 | |
|
Maybe the description is not clear enough. It is to filter out all numbers and letters in the document and only leave Chinese characters.
|
|
| Floor4 vkill | Posted 2007-04-28 07:07 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
| Floor5 lxmxn | Posted 2007-04-28 07:11 |
| 版主 Posts 4,938 Credits 11,386 | |
|
vkill commands, it's a bit troublesome with batch processing.
|
|
| Floor6 vkill | Posted 2007-04-28 07:47 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
|
sed "s/[0-9a-zA-Z]/ /g" life
|
|
| Floor7 youxi01 | Posted 2007-04-28 08:06 |
| 高级用户 Posts 247 Credits 846 From 湖南==》广东 | |
|
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: 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) |
|
| Floor8 zhoushijay | Posted 2007-04-28 08:20 |
| 高级用户 Posts 375 Credits 845 | |
|
```
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. ``` |
|
| Floor9 xixi27 | Posted 2007-04-28 22:50 |
| 新手上路 Posts 6 Credits 14 | |
|
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! |
|
| Floor10 huzixuan | Posted 2007-04-29 00:53 |
| 高级用户 Posts 219 Credits 537 From 芜湖 | |
|
```
@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 ] |
|
| Floor11 xixi27 | Posted 2007-04-29 02:24 |
| 新手上路 Posts 6 Credits 14 | |
|
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! |
|
| Floor12 lxmxn | Posted 2007-04-29 03:46 |
| 版主 Posts 4,938 Credits 11,386 | |
|
The reason for the appearance of "ECHO is off" is that the value after the echo command is empty.
|
|
| Floor13 huzixuan | Posted 2007-04-29 06:15 |
| 高级用户 Posts 219 Credits 537 From 芜湖 | |
|
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.
|
|
| Floor14 huzixuan | Posted 2007-04-29 06:37 |
| 高级用户 Posts 219 Credits 537 From 芜湖 | |
|
I don't know which one is more efficient.
|
|
| Floor15 xixi27 | Posted 2007-04-29 07:13 |
| 新手上路 Posts 6 Credits 14 | |
|
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? |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |