2016-03-23 5 views
1

私は最後尾に、私は、彼らがそれほど長くないように、これらの行のうちのジャンクの多くをカットするいくつかの行だけを切り取り、他の行は未処理のままにしておくことはできますか?

Mar 22 23:26:18.793031 localhost my_process[1123]: (my_id) contents of actual log output 
Mar 22 23:26:18.946769 localhost my_process[1123]: (my_id) more singe line contents 
Mar 22 23:26:18.955423 localhost my_process[1123]: (my_id) 
**** 
* this log statement has a bunch of lines 
**** 

に似た形式を持つログファイルが欲しいです。しかし、私は日付などで始まる行だけをカットし、他の行は残しておきたい。

23:26:18 my_process[1123]: contents of actual log output 
23:26:18 my_process[1123]: more singe line contents 
23:26:18 my_process[1123]: 
**** 
* this log statement has a bunch of lines 
**** 

これは私が行っているパイプラインですが、すべてのラインをカットしています。

# first cut out the unwanted fields 
# then cut out the unwanted decimal part of the timestamp 
tail -f mylog.txt | cut -d " " -f 3,5,7- | cut -c 1-8,16- 

共通の日付パターンで始まらない行を探して、未処理のままにする方法はありますか?

おかげ

答えて

1

あなたはこのようにawkを使用することができます:

awk '/ [0-9]{2}:[0-9]{2}:[0-9]{2}/{ 
    split($0, a, /: \([^)]+\) /) 
    sub(/\.[0-9]+/, "", $3) 
    print $3, $5, a[2] 
    next 
} 1' file.log 

23:26:18 my_process[1123]: contents of actual log output 
23:26:18 my_process[1123]: more singe line contents 
23:26:18 my_process[1123]: 
**** 
* this log statement has a bunch of lines 
**** 

/ [0-9]{2}:[0-9]{2}:[0-9]{2}/は、入力ラインのhh:mm:ssで特定のパターンを検索し、行のみを解析します。残りの行はそのまま印刷されます。