Windows cmd - findstr 和 gawk 或者如何提取以下数据
我想知道是否可以使用 findstr 和/或 gawk 来完全按照我需要的方式返回 Windows cmd 的输出。我目前正在返回原始输出,然后删除空白行,并解析出我需要的内容。作为一种学习,我希望我能看到如何做得更好。
原始输出:
Change 2086888 on 2012/01/23 by user1@server1
test_description_1.2.3.4@29816
Change 2086888 on 2012/01/23 by user1@server2
test_description2_4.5.6.7@29816
Change 2078677 on 2012/01/20 by user2@server1
test_description3_7.8.9.10@29816
我获取该输出并使用 php 将其解析为:
1. 2086888,test_description_1.2.3.4@29816
2. 2086888,test_description2_4.5.6.7@29816
3. 2078677,test_description3_7.8.9.10@29816
为了让自己更容易一些,我通过将其管道传输到 findstr 并使用 /V "^$" 来从输出中删除空行。所以是|查找str /V“^$”。
如何直接从命令行获取用 php 解析的输出?
I was wondering if it's possible to use findstr and/or gawk to return the output of a windows cmd exactly how I need it to be. I'm currently returning the output raw, then stripping out the blank lines, and parsing out what I need. Just as a learning thing, I was hoping I could see how this can be done better.
The raw output:
Change 2086888 on 2012/01/23 by user1@server1
test_description_1.2.3.4@29816
Change 2086888 on 2012/01/23 by user1@server2
test_description2_4.5.6.7@29816
Change 2078677 on 2012/01/20 by user2@server1
test_description3_7.8.9.10@29816
I take that output and parse it out to this with php:
1. 2086888,test_description_1.2.3.4@29816
2. 2086888,test_description2_4.5.6.7@29816
3. 2078677,test_description3_7.8.9.10@29816
To make it a little easier on myself, I remove the blank lines from the output by piping it to findstr and using /V "^$". So it's | findstr /V "^$".
How can I get the output that I parse out with php directly from the command line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
cmd.exe 中的
for
命令会跳过空行,因此这样解析可能会更容易:for
command in cmd.exe skips blank lines, so it may be easier to parse it this way: