Hallo Ich suche eine McAfee-Protokolldatei zu trimmen und entfernen Sie alle "ist OK" und andere gemeldete Instanzen, die ich nicht interessiert. Bevor wir ein Shell-Skript verwendeten, das die Option -v für grep ausnutzte, wollen wir nun ein Python-Skript schreiben, das sowohl auf Linux als auch auf Windows funktioniert. Nach ein paar Versuchen konnte ich eine Regex in einem Online-Regex-Builder verwenden, aber es fällt mir schwer, sie in mein Skript zu implementieren. Online REGEX BuilderInverse-Match-Hilfe in Python
Edit: Ich möchte, dass die entfernen „ist OK“, „ist ein broken“, „ist ein Blocklinien“, und Linien „Datei konnte nicht geöffnet werden“, so dann bin ich nur mit einer Datei links nur die Probleme, die ich interessiert bin Eine Art von dergleichen wie dies in der Schale.
grep -v "is OK" ${OUTDIR}/${OUTFILE} | grep -v "is a broken" | grep -v "file could not be opened" | grep -v "is a block" > ${OUTDIR}/${OUTFILE}.trimmed 2>&1
ich lese in und durch die Datei suchen hier:
import re
f2 = open(outFilePath)
contents = f2.read()
print contents
p = re.compile("^((?!(is OK)|(file could not be opened)| (is a broken)|(is a block)))*$", re.MULTILINE | re.DOTALL)
m = p.findall(contents)
print len(m)
for iter in m:
print iter
f2.close()
Eine Probe der Datei ich bin versuchen zu suchen:
eth0
10.0.11.196
00:0C:29:AF:6A:A7
parameters passed to uvscan: --DRIVER /opt/McAfee/uvscan/datfiles/current -- ANALYZE --AFC=32 ATIME-PRESERVE --PLAD --RPTALL RPTOBJECTS SUMMARY --UNZIP -- RECURSIVE --SHOWCOMP --MIME --THREADS=4 /tmp
temp XML output is: /tmp/HIQZRq7t2R
McAfee VirusScan Command Line for Linux64 Version: 6.0.5.614
Copyright (C) 2014 McAfee, Inc.
(408) 988-3832 LICENSED COPY - April 03 2016
AV Engine version: 5700.7163 for Linux64.
Dat set version: 8124 created Apr 3 2016
Scanning for 670707 viruses, trojans and variants.
No file or directory found matching /root/SVN/swd-lhn-build/trunk/utils/ATIME-PRESERVE
No file or directory found matching /root/SVN/swd-lhn-build/trunk/utils/RPTOBJECTS
No file or directory found matching /root/SVN/swd-lhn-build/trunk/utils/SUMMARY
/tmp/tmp.BQshVRSiBo ... is OK.
/tmp/keyring-F6vVGf/socket ... file could not be opened.
/tmp/keyring-F6vVGf/socket.ssh ... file could not be opened.
/tmp/keyring-F6vVGf/socket.pkcs11 ... file could not be opened.
/tmp/yum.log ... is OK.
/tmp/tmp.oW75zGUh4S ... is OK.
/tmp/.X11-unix/X0 ... file could not be opened.
/tmp/tmp.LCZ9Ji6OLs ... is OK.
/tmp/tmp.QdAt1TNQSH ... is OK.
/tmp/ks-script-MqIN9F ... is OK.
/tmp/tmp.mHXPvYeKjb/mcupgrade.conf ... is OK.
/tmp/tmp.mHXPvYeKjb/uvscan/uninstall-uvscan ... is OK.
/tmp/tmp.mHXPvYeKjb/mcscan ... is OK.
/tmp/tmp.mHXPvYeKjb/uvscan/install-uvscan ... is OK.
/tmp/tmp.mHXPvYeKjb/uvscan/readme.txt ... is OK.
/tmp/tmp.mHXPvYeKjb/uvscan/uvscan_secure ... is OK.
/tmp/tmp.mHXPvYeKjb/uvscan/signlic.txt ... is OK.
/tmp/tmp.mHXPvYeKjb/uvscan/uvscan ... is OK.
/tmp/tmp.mHXPvYeKjb/uvscan/liblnxfv.so.4 ... is OK.
Aber ich bekomme nicht die richtige Ausgabe. Ich habe versucht, sowohl die MULTILINE- als auch die DOTALL-Optionen zu entfernen und bekomme immer noch nicht die richtige Antwort. Unten ist die Ausgabe, wenn mit DOTALL und MULTILINE ausgeführt wird.
9
('', '', '', '', '')
('', '', '', '', '')
('', '', '', '', '')
('', '', '', '', '')
('', '', '', '', '')
('', '', '', '', '')
('', '', '', '', '')
('', '', '', '', '')
('', '', '', '', '')
Jede Hilfe würde sehr geschätzt werden !! Vielen Dank!!
Mit 're.findall' extrahieren Sie alle erfassten Werte. Probieren Sie 're.compile (r '^ (?: (?! \ B (?: Ist OK | Datei konnte nicht geöffnet werden | ist ein Fehler | ist ein Block) \ b).) + $', Re.DOTALL | re.MULTILINE) 'mit' re.findall' –
Können Sie zeigen, was Sie Zielausgabe ist, werde ich es sofort lösen. –
Ich denke, ich war nicht klar, ich möchte alle Zeilen, die nicht enden mit "ist OK" oder "ist eine kaputte" Art wie wenn ich laufen würde: grep -v "ist OK" $ {OUTDIR}/$ {OUTFILE} | grep -v "ist ein kaputtes" | grep -v "Datei konnte nicht geöffnet werden" | grep -v "ist ein Block"> $ {OUTDIR}/$ {OUTFILE} .trimmed 2> & 1 –