Board logo

标题: [文本处理] 求助批处理for tokens去除某符号后面内容无法输出到文本中 [打印本页]

作者: leon    时间: 2009-3-31 13:21     标题: 求助批处理for tokens去除某符号后面内容无法输出到文本中

下面是一个log.txt文件
C:\NTtest\logcompare>net use s: /delete /y
C:\NTtest\logcompare>net use s: [url=file://\\10.20.25.115\nttest]\\10.20.25.115\nttest[/url]
The command completed successfully.

C:\NTtest\logcompare>copy s:\cshdpm5.txt s:\logcompare\cshdpm5.txt
        1 file(s) copied.
C:\NTtest\logcompare>del s:\logcompare\cshdpm5.txt
C:\NTtest\logcompare>s:
S:\>RTOPCB /S dwn.DTF
IBM iSeries Access for Windows
Version 5  Release 3  Level 0
Transfer data from iSeries
(C) Copyright IBM Corporation and Others 1984, 2003.  All rights reserved.
U.S. Government Users Restricted Rights - Use, duplication or disclosure
  restricted by GSA ADP Schedule Contract with IBM Corp.
Licensed Materials - Property of IBM
Transfer file: dwn.DTF
Receive completed successfully.
Rows transferred: 41
S:\>rfrompcb /s upload.dtt
IBM iSeries Access for Windows
Version 5  Release 3  Level 0
Transfer data to iSeries
(C) Copyright IBM Corporation and Others 1984, 2003.  All rights reserved.
U.S. Government Users Restricted Rights - Use, duplication or disclosure
  restricted by GSA ADP Schedule Contract with IBM Corp.
Licensed Materials - Property of IBM
Transfer file: upload.dtt
Send completed successfully.
Rows transferred: 41

我想要在蓝色字体的2行冒号以后的数字不显示,其他所有的输出到comparelog中去,写了如下命令:
for /f "delims=:  tokens=17" %%i in (log.txt) do echo %%i  > comparelog.txt
但是没有comparelog文件生成,是我命令用法不对吗?谢谢!



[ 本帖最后由 leon 于 2009-3-31 13:58 编辑 ]
作者: Batcher    时间: 2009-3-31 14:09

请问楼主为何要使用tokens=17呢,它在此处的作用是什么?
作者: leon    时间: 2009-3-31 14:22

额..本来我是想第17行就是蓝色字体的第一个地方,然后那一行只取:之前的内容,其他行内容不变还正常输出
作者: Batcher    时间: 2009-3-31 14:23     标题: 回复 3楼 的帖子

可以先去学习一下tokens的用法:http://bbs.bathome.net/thread-2189-1-1.html
作者: xeqxerxes    时间: 2009-4-1 10:54

我倒是有另一种办法能达到同样目的
setlocal ENABLEDELAYEDEXPANSION
set STR1=Rows transferred: 41
SET STR2=Rows transferred:
for /f "tokens=* delims=" %%a in (log.txt) do (
set n=%%a
set n=!n:%STR1%=%STR2%!
echo !n!>>comparelog
)
作者: leon    时间: 2009-4-2 10:00

谢谢!学习下!
作者: Lumiere    时间: 2009-4-2 11:21

鉴于文本中有数字41的的行就是蓝色字体部分的两行,所以用字符串替换就可以。
setlocal enabledelayedexpansion
for /f "delims=" %%a in (log.txt) do set var=%%a&echo !var:41=!>>logcompare.txt
pause




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2