bir satırlı değişken uzunlukta log dosyası ayrıştırma:Ben aşağıdaki parametreleri uyan bir günlük dosyası ayrıştırır bir 'grep' ya çözüm gibi 'pcregrep -M' yararlanmak isterler
- Her günlük girdisi uzunluğunda birden çok satır olabilir günlük girdisinin
- Birinci satır Ben Her anahtar dönmek isteyeyim aşağıdaki örnekte
Yani daha sonra bir satırda görünüyor
Log file: 01 Feb 2010 - 10:39:01.755, DEBUG - KEY1:randomtext blah blah2 T blah3 T blah4 F blah5 F blah6 blah7 01 Feb 2010 - 10:39:01.757, DEBUG - KEY1:somethngelse 01 Feb 2010 - 10:39:01.758, DEBUG - KEY2:randomtest this is a test 01 Feb 2010 - 10:39:01.760, DEBUG - KEY1:more logs here 01 Feb 2010 - 10:39:01.762, DEBUG - KEY1:eve more here this is another multiline log entry keeps on going but not as long as before 01 Feb 2010 - 10:39:01.763, DEBUG - KEY2:testing test test test end of key2 01 Feb 2010 - 10:39:01.762, DEBUG - KEY1:but key 1 is still going and going and going and going and going and going and going and going and going and going and going and going and going okay enough 01 Feb 2010 - 10:39:01.762, DEBUG - KEY3:and so on and on
Desired output of searching for KEY1: 01 Feb 2010 - 10:39:01.755, DEBUG - KEY1:randomtext blah blah2 T blah3 T blah4 F blah5 F blah6 blah7 01 Feb 2010 - 10:39:01.757, DEBUG - KEY1:somethngelse 01 Feb 2010 - 10:39:01.760, DEBUG - KEY1:more logs here 01 Feb 2010 - 10:39:01.762, DEBUG - KEY1:eve more here this is another multiline log entry keeps on going but not as long as before 01 Feb 2010 - 10:39:01.762, DEBUG - KEY1:but key 1 is still going and going and going and going and going and going and going and going and going and going and going and going and going okay enoughben böyle bir şey yapmaya çalışıyordum: '(. * \ N) key1 +'
pcregrep -M kesinlikle logfile'a
ama doğru çalışmıyor.
Bir girişin sonunu ne tanımlar? Bir girişteki satırların bir rakamla başlayamayacağı garanti edilir, ancak yeni bir girişi tanımlayan bir satır olur mu? –
Bu, normal ifadelerden ziyade küçük bir betik kullanılarak daha kolay olabilir. Bunu yapmamanın herhangi bir sebebi var mı? –