2016-03-23 14 views
1

Ben kuyruğunaBaşkalarını işlenmemişken yalnızca bazı satırları nasıl kesiyorum?

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 
**** 

onlar kadar uzun olmayacak şekilde bu satırların dışarı önemsiz bir sürü kesmek istiyor benzer bir biçime sahip bir günlük dosyası istiyorum. Ancak, sadece diğer satırları tek başına bırakırken, sadece tarihle başlayan satırları kesmek istiyorum. Aşağıdaki gibi olmalıdır:

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 
**** 

Bu benim ilerlediğim boru hattı, ancak tüm satırları kesiyor.

# 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- 

Ben bu ortak tarih deseni ile başlar ve sadece işlenmemiş aracılığıyla bu satırları izin vermeyin hatları için görünebilir bir yolu var mı?

Teşekkür

cevap

1

Böyle awk kullanabilirsiniz:

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}/ giriş satırına hh:mm:ss ile belirli model aramak ve sadece bu satırları ayrıştırmak olacaktır. Hatların geri kalanı olduğu gibi basılacaktır.

İlgili konular