标题: 当findstr遇到文本中的特殊字符,比如>
[打印本页]
作者: sinbao
时间: 2007-10-13 17:54
标题: 当findstr遇到文本中的特殊字符,比如>
test.txt内容为
486 1
-->
aaaa
487 2
-->
bbbb
我的脚本:
@echo off
setlocal enabledelayedexpansion
set file=test.txt
for /f "usebackq delims=" %%a in ("%file%") do (
set tmp=%%a
echo !tmp: =!|findstr /i "^[0-9][0-9][0-9]"
)
endlocal
goto :EOF
我要想要输出为:
4861
4872
然而却得到:
4861
命令语法不正确。
4872
命令语法不正确。
请问这个问题怎么解决?
[
Last edited by sinbao on 2007-10-13 at 06:47 PM ]
作者: junchen2
时间: 2007-10-13 17:58
findstr /i "^[0-9][0-9][0-9]" test.txt
作者: sinbao
时间: 2007-10-13 18:04
楼上的结果:
486 1
487 2
不是我要的...
作者: junchen2
时间: 2007-10-13 18:16
@echo off
setlocal enabledelayedexpansion
set file=test.txt
for /f " delims=" %%a in ('type test.txt ^|findstr /i "^[0-9][0-9][0-9]"') do (
set tmp=%%a
echo !tmp: =!
)
endlocal
pause
[
Last edited by junchen2 on 2007-10-13 at 06:21 PM ]
作者: sinbao
时间: 2007-10-13 18:29
junchen2:
你知道我的输出为什么会有: "命令语法不正确。"这种提示吗?
作者: sinbao
时间: 2007-10-13 18:30
继续---
我的脚本:
@echo off & setlocal enabledelayedexpansion
set file=test.txt
for /f "usebackq delims=" %%a in ("%file%") do (
set tmp=%%a
echo !tmp:^>=!|findstr /i "^[0-9][0-9][0-9]">NUL && echo 数字||(
echo !tmp^>=!|findstr /i "^[a-z][a-z][a-z]">NUL && echo 字母||(
echo 什么都不是
)
)
)
endlocal & goto :EOF
我要的输出:
数字
什么都不是
字母
数字
什么都不是
字母
但是我的输出:
数字
字母
字母
数字
字母
字母
作者: sinbao
时间: 2007-10-13 18:46
@echo off & setlocal enabledelayedexpansion
set file=test.txt
for /f "usebackq delims=" %%a in ("%file%") do (
set tmp=%%a
set tmp=!tmp:^>=^^^>!
set tmp=!tmp:^|=^^^|!
set tmp=!tmp:^<=^^^<!
echo !tmp!|findstr /i "^[0-9][0-9][0-9]">NUL && echo 数字||(
echo !tmp!|findstr /i "^[a-z][a-z][a-z]">NUL && echo 字母||(
echo 什么都不是
)
)
)
endlocal & goto :EOF
解决了,但是这样做似乎太麻烦了...
作者: junchen2
时间: 2007-10-13 18:46
echo !tmp^>=!|自己看看是马是虎!?
作者: sinbao
时间: 2007-10-13 19:05
恩,多谢junchen2
实际问题是这样的
http://www.cn-dos.net/forum/viewthread.php?tid=34352&fpage=1
有兴趣可以帮帮忙~~
前面发错链接了,更新了一下~~
[
Last edited by sinbao on 2007-10-13 at 10:02 PM ]