根据时间戳提取部分日志文件

时间:2012-09-18 09:37:25

标签: bash sed

我有一个应用程序附加到同一个日志文件。由于这个文件相当大(大约8 GB),我想根据行开头的时间戳提取部分。

-bash-3.2$ cat application.log | egrep --color "Starting Application|Exception"
08:46:01.328 [main] INFO  Starting Application...
09:14:53.670 [Thread-1] ERROR Resolver - Caught exception -> com.jgoodie.AuthzException: Authorization failed
Caused by: com.jgoodie.AuthzException: Authorization failed
09:56:15.739 [main] INFO  Starting Application...
10:17:08.932 [Thread-1] ERROR Resolver - Caught exception -> com.jgoodie.AuthzException: Authorization failed
Caused by: com.jgoodie.AuthzException: Authorization failed

在上面的例子中,我想提取应用程序第一次运行的日志(08:46:01.328和09:56:15.739之间)。有没有简单的方法(最好是一个班轮)来做到这一点?

由于

2 个答案:

答案 0 :(得分:6)

sed -n '/08:46:01.328/,/09:56:15.739/p' application.log

答案 1 :(得分:2)

perl -lne 'if(/^08:46:01.328/.../^09:56:15.739/){print}' your_file