質問

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.

役に立ちましたか?

解決

If the records are sorted by time, you can just

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

Beware, if there are more records with the end time, only the first one will be printed. You can improve it by

sed -n '/start/,/end/{p;d};/end/p'

他のヒント

does this work for you? (didn't test)

awk -F' |:'  'BEGIN{m="Nov";d=20;sh=13;eh=16}$1==m && $2==d && $3>=sh && $3<=eh' file
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top