1

我需要从文件中提取一些数据以将它们应用于特定过程。文件结构如下所示

      some title information at file header

      I001=send login information to the system
       connection is OK            
      A001=System has answered: "you are connected"


      I002=press the log out button
      A002=system has answered: "You have been disconnected"
      disconnection is OK

      I003= timeout is 10
      If timeout occurs, refresh view and then check if connection is come again 
      Else retry refreshment until you are connected to the system 

我的目标是让 I001,I002,I003,... 保持在一条线上。为此,我写

    more +1 %1 | findstr /v /r "^A...=.*"   

但我明白了

       I001=send login information to the system
       connection is OK
       I002=press the log out button
       I003= timeout is 10
       If timeout occurs, refresh view and then check if connection is come again. 
       Else retry refreshment until you are connected to the system

代替

      I001=send login information to the system
      I002=press the log out button     
      I003= timeout is 10

另一方面,请让我知道如何立即通过管道将此结果传递给使用文件作为参数的 vbs 脚本。当我使用

         findstr "I[0-9][0-9][0-9]" "%~1"|cscript myscript.vbs, 

我在 fsoObj.opentextfile(wscript.arguments(0),1).readall 行出现错误,使用 fsoObj=createobject("scripting.filesystemobject")。

非常感谢您的帮助

4

3 回答 3

1

如果您搜索I+ 三个数字,只需使用:

findstr "I[0-9][0-9][0-9]" "%~1"

.. 无论如何,表达式之前或之后是什么,more也不需要。

于 2013-06-03T17:04:36.210 回答
0

首先,摆脱该/v选项,它与您想要的完全相反。

/V 只打印不包含匹配的行。

你也在寻找A一开始,但你想要I,所以把它改成

more +1 %1 | findstr /r "^I...=.*"

注意:您上面的文件文本缩进了 6 个空格。在这种情况下使用

more +1 %1 | findstr /r "I...=.*"

(没有^, 因为它只会匹配以开头的行,I之前没有空格。)

于 2013-06-03T16:40:45.003 回答
0

我不是 100% 确定我理解正确,但如果你只想要以 开头的行I...=,那么你可以这样做:

type %1 | findstr /r "I...=.*"

鉴于您的输入,这将打印...

      I001=send login information to the system
      I002=press the log out button
      I003= timeout is 10

...我认为这就是你想要的。

于 2013-06-03T16:35:58.790 回答