如何使用Windows命令行工具或批处理文件从日志文件中提取行? [英] How to extract rows from a log file using Windows command line tools or batch file?

查看:117
本文介绍了如何使用Windows命令行工具或批处理文件从日志文件中提取行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用本机Windows命令行工具或批处理文件(.bat)从日志文件中提取某些行.这是一个示例日志文件:

I would like to extract certain rows from a log file using native Windows command line tools or batch file (.bat). Here's a sample log file:

2009-12-07 14:32:38,669 INFO  Sample log
2009-12-07 14:32:43,029 INFO  Sample log
2009-12-07 14:32:45,841 DEBUG Sample log
2009-12-07 14:32:45,841 DEBUG Sample log
2009-12-07 14:32:52,029 WARN  Sample log
2009-12-07 14:32:52,466 INFO  Sample log

如何提取和打印带有标签"WARN"的行?如何使用PowerShell执行此操作?

How to extract and print lines which have tag "WARN"? How to do this with PowerShell?

推荐答案

一种方法:

findstr WARN log.txt

更复杂:

for /f "tokens=1,2,3,4* delims=, " %i in (log.txt) do @if "%l"=="WARN" echo %i %j %m

OUTPUT:
2009-12-07 14:32:52 Sample log

这篇关于如何使用Windows命令行工具或批处理文件从日志文件中提取行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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