|
xixi27
新手上路

积分 14
发帖 6
注册 2007-4-28
状态 离线
|
『楼 主』:
过滤掉文本中未知的数字和字母
使用 LLM 解释/回答一下
请问如何过滤掉一个文本文件中所有的未知的数字和字母,并另存在一个新文本。这些数字和字母是穿插在文档中的。
如:细细哈哈12咚咚ajs
思索
今天0D12
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
|
|
2007-4-28 06:13 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
是要过滤掉字母和数字呢?还是过滤掉中文字符?请把问题描述再具体一点,方便大家阅读。
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.
|
|
2007-4-28 06:47 |
|
|
xixi27
新手上路

积分 14
发帖 6
注册 2007-4-28
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
可能没描述清楚,是把文档中所有的数字及字母过滤掉,只留下汉字
Maybe the description is not clear enough. It is to filter out all numbers and letters in the document and only leave Chinese characters.
|
|
2007-4-28 06:52 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
|
2007-4-28 07:07 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
vkill 把命令写出来吧,用批处理有点小麻烦。
vkill commands, it's a bit troublesome with batch processing.
|
|
2007-4-28 07:11 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
sed "s/[0-9a-zA-Z]/ /g" life
sed "s// /g" life
|
|
2007-4-28 07:47 |
|
|
youxi01
高级用户
   
积分 846
发帖 247
注册 2006-10-27 来自 湖南==》广东
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
简单的还是可以处理的(不考虑特殊字符,对很多的空格处理不太合理)
利用批处理来处理,简单的演示代码:
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in (test.txt) do (
call :Check "%%i" OK
echo !OK!
)
pause>nul
:Check 处理对象 传回结果
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!
)
说明:test.txt中的内容,为要处理的文本内容
处理对象,小文本,且不含特殊字符(因为特殊字符在此未考虑)
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)
|
|
2007-4-28 08:06 |
|
|
zhoushijay
高级用户
    Autowalk
积分 845
发帖 375
注册 2007-3-3
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
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,,"过滤"
set newtxt=fso.createtextfile("22.txt")
newtxt.write gettxt
'vbs版的!
'11.txt为需要过滤的文件,请自己修改,22.txt为保存后的文本,可以不改。
```
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.
```
|
|
2007-4-28 08:20 |
|
|
xixi27
新手上路

积分 14
发帖 6
注册 2007-4-28
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
多谢各位的帮忙,麻烦的是我要处理的文本里面有很多空格,而且如果数字或者字母单独在一行内时,过滤后会有问题。
另外,会出现 “ECHO处于关闭状态 “ 的提示,这是什么意思啊?
请各位帮忙!谢谢!
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!
|
|
2007-4-28 22:50 |
|
|
huzixuan
高级用户
   
积分 537
发帖 219
注册 2006-10-31 来自 芜湖
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
@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 ]
```
@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 ]
|

江湖远
碧空长
路茫茫
一个人漫无目的的奔跑,风,刺骨的冷.... |
|
2007-4-29 00:53 |
|
|
xixi27
新手上路

积分 14
发帖 6
注册 2007-4-28
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
楼上的回答可以解决数字或者字母单独成行的问题,但是如果数字或者字母之间有空格的话还是存在问题啊!
另外,能否解答一下出现 “ECHO处于关闭状态” 的问题呢? 非常感谢!
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!
|
|
2007-4-29 02:24 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
出现“ECHO处于关闭状态”的原因是echo命令后面的值为空。
The reason for the appearance of "ECHO is off" is that the value after the echo command is empty.
|
|
2007-4-29 03:46 |
|
|
huzixuan
高级用户
   
积分 537
发帖 219
注册 2006-10-31 来自 芜湖
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
先将 变量中 所有空格替换掉,然后依次替换掉 数字 以及 字母
最后读出变量
已经修改 10 楼代码
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.
|

江湖远
碧空长
路茫茫
一个人漫无目的的奔跑,风,刺骨的冷.... |
|
2007-4-29 06:15 |
|
|
huzixuan
高级用户
   
积分 537
发帖 219
注册 2006-10-31 来自 芜湖
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
不知道哪个效率高一些
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," ") ' 将 0 - 9 数字置空
next
for i = 65 to 90
str = replace(str,chr(i)," ") ' 将 a-z 小写字母置空
next
FOR J = 97 TO 122
STR = REPLACE(STR,CHR(J)," ") ' 将 A-Z 大写字母置空
NEXT
wfile.write str
wfile.close
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
|

江湖远
碧空长
路茫茫
一个人漫无目的的奔跑,风,刺骨的冷.... |
|
2007-4-29 06:37 |
|
|
xixi27
新手上路

积分 14
发帖 6
注册 2007-4-28
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
多谢huzixuan,我刚刚已经在你原来代码的基础上解决了问题,跟你的想法一样!
同时也谢谢其他各位的帮忙,这几天刚刚接触批处理,不过在这里真的学到了很多的东西,谢谢大家了!
还有一个问题,“echo."代表啥啊?
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?
|
|
2007-4-29 07:13 |
|