使用Windows命令行或Python查找带有模式的文本行 [英] Find a line of text with a pattern using Windows command line or Python

查看:94
本文介绍了使用Windows命令行或Python查找带有模式的文本行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要运行一个命令行工具来验证文件并显示大量有关该文件的信息.我可以将此信息导出到txt文件,但其中包含很多额外的数据.我只需要一行用于文件:

I need to run a command line tool that verifies a file and displays a bunch of information about it. I can export this information to a txt file but it includes a lot of extra data. I just need one line for the file:

签名被打上时间戳:2012年5月24日星期四"

"The signature is timestamped: Thu May 24 17:13:16 2012"

时间可能会有所不同,但是我只需要提取这些数据并将其放入文件中即可.有没有一种好的方法可以从命令行本身或python做到这一点?我计划使用Python查找并下载要验证的文件,然后运行命令行工具进行验证,以便它可以获取数据,然后通过电子邮件发送该数据.

The time could be different, but I just need to extract this data and put it into a file. Is there a good way to do this from the command line itself or maybe python? I plan on using Python to locate and download the file to be verified, then run the command line tool to verify it so it can get the data then send that data in an email.

这是在Windows PC上.

This is on a windows PC.

感谢您的帮助

推荐答案

您无需使用Python即可执行此操作.如果您使用的是Unix环境,则可以直接在命令行中使用fgrep并将输出重定向到另一个文件.

You don't need to use Python to do this. If you're using a Unix environment, you can use fgrep right from the command-line and redirect the output to another file.

fgrep "The signature is timestamped: " input.txt > output.txt

在Windows上,您可以使用:

On Windows you can use:

find "The signature is timestamped: " < input.txt > output.txt

这篇关于使用Windows命令行或Python查找带有模式的文本行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆