あるファイルの特定のテキストを別のファイルにコピーする

あるファイルの特定のテキストを別のファイルにコピーする

次のテキストファイルがあります。

Start find in flight queries
2018-03-05 15:50:02,069:INFO:######################################
Start find completed queries
2018-03-05 15:50:02,070:INFO:Starting new HTTPS connection (1): server060
2018-03-05 15:50:02,083:DEBUG:"GET /queries?json HTTP/1.1" 401 0
2018-03-05 15:50:02,084:INFO:Resetting dropped connection: server060
2018-03-05 15:50:02,095:DEBUG:"GET /queries?json HTTP/1.1" 200 19059
2018-03-05 15:50:02,099:INFO:######################################
Start find in flight queries

日時多様性5分に一度。コピーする必要がありますついに日付と時刻を別のファイルに転送します。この例では、2018-03-05 15:50:02です。どんな提案にも感謝します。私は過去にいくつかの正規表現を試しましたが、うまく使用できませんでした。

ベストアンサー1

tac+grep解決策:

tac input.txt | grep -Eo -m1 '^[0-9]{4}(-[0-9]{2}){2} [0-9]{2}(:[0-9]{2}){2}' > last_date.txt

おすすめ記事