Traitement log avec awk

Modi-tintin Messages postés 6 Date d'inscription   Statut Membre Dernière intervention   -  
Modi-tintin Messages postés 6 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

j'ai un fichier de log composé de paragraphes séparés par une ligne vide et j'aimerai faire un autre fichier avec dedans que les paragraphes qui ont le mot tintin (par exemple)

rrrrrrrrrrrrrrr
rrrrrrrrrrrrrrr
rrrrrrrrrrrrrrr

ffffjjjjjjj tintin
uuuuuuuu
rrrrrrrrrrrrrrr
rrrrrrrrrrrrrrrr
ggggggggggggg

tttttttttttttt
tttttt
hhhhhhhhh


:)

comment faire ?

par avance merci

2 réponses

dubcek Messages postés 18789 Date d'inscription   Statut Contributeur Dernière intervention   5 637
 
hello
awk -v RS="" '/tintin/' log > log2
1
Modi-tintin Messages postés 6 Date d'inscription   Statut Membre Dernière intervention  
 
#!/usr/bin/env python

import re

with open("./tintin.log") as f:
buffer = f.read()

paragraphs = re.split("\r\n\r\n", buffer)

for paragraph in paragraphs:
if re.search("tintin", paragraph, re.MULTILINE):
print(paragraph)

awk fonctionne pas avec python ok
-1