Quiero ser capaz de utilizar un 'grep' o '-M pcregrep' como solución que analiza un archivo de registro que se ajuste a los siguientes parámetros:análisis de un archivo de registro de longitud variable multilínea
- Cada entrada del registro puede haber múltiples líneas de longitud
- Primera línea de entrada de registro tiene la llave que quiero buscar
- aparece Cada tecla en más de una línea de
Así, en el ejemplo a continuación me gustaría volver cada línea que h como KEY1 en él y todas las líneas de apoyo debajo de él hasta el siguiente mensaje de registro.
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 enough
yo estaba tratando de hacer algo como: '(. * \ N) TECLA1 +'
pcregrep -M archivo de registro
pero definitivamente no funciona bien.
¿Qué define el final de una entrada? ¿Se garantiza que las líneas dentro de una entrada no comenzarán con un dígito, sino que una línea que define una nueva entrada lo hará? –
Esto podría ser más fácil utilizando un pequeño script en lugar de una expresión regular. ¿Alguna razón para no hacer eso? –