我在测试数据中添加了另外 2 条记录以确保这确实有效:
2014-03-19 14:05:53,999 [NfxAgent....
2014-03-20 14:05:53,164 [NfxAgent....
但我认为您不能为此使用grep。这是一个 awk 解决方案:
$ grep sent grepTest_20140321.txt| awk '$0 > "2014-03-20 14:05:54"'
2014-03-20 14:05:54,038 [NfxAgent....
2014-03-20 14:05:54,164 [NfxAgent....
2014-03-20 14:05:54,298 [NfxAgent....
2014-03-20 14:05:54,414 [NfxAgent....
2014-03-20 14:05:54,787 [NfxAgent....
编辑
“如果我们需要以与 2014-03-21 10:04:14,018 相同的格式指定结束时间怎么办?”
并且我添加了 3 行测试数据来确认第 2 种情况:
2014-03-21 10:04:14,017 [NfxAgent....
2014-03-21 10:04:14,018 [NfxAgent....
2014-03-22 10:04:14,999 [NfxAgent....
结果显示您指定范围内的一条新记录。
awk '$0 ~ "sent" && $0 > "2014-03-20 14:05:54" && $0 < "2014-03-21 10:04:14,018"' grepTest_20140321.txt
2014-03-20 14:05:54,038 [NfxAgent....
2014-03-20 14:05:54,164 [NfxAgent....
2014-03-20 14:05:54,298 [NfxAgent....
2014-03-20 14:05:54,414 [NfxAgent....
2014-03-20 14:05:54,787 [NfxAgent....
2014-03-21 10:04:14,017 [NfxAgent....
IHTH