1

Want to get specific hour to another and save output. First hour is my start point for example:

Nov 20 13:42:52 host sendmail[14819]: qAKCgpxF014819: Milter: read returned -1: Connection reset by mail.yahoo.com

And my finish point is:

Nov 20 16:22:23 host sendmail[16326]: qAKCgpxF016326: Milter: read returned -1: Connection reset by mail.yahoo.com

I need to save all data from my start point to my finish point into file only.

4

2 回答 2

1

如果记录按时间排序,您可以

sed -n '/^Nov 20 13:42:52/,/^Nov 20 16:22:23/p' input.log > output.log

请注意,如果结束时间的记录更多,则只会打印第一个。您可以通过以下方式改进它

sed -n '/start/,/end/{p;d};/end/p'
于 2012-11-21T13:17:55.620 回答
1

这对你有用吗?(没有测试)

awk -F' |:'  'BEGIN{m="Nov";d=20;sh=13;eh=16}$1==m && $2==d && $3>=sh && $3<=eh' file
于 2012-11-21T12:42:15.887 回答