Moin, ich verwende seit einiger Zeit Bogofilter zusammen mit KMail. Meine eMails sind alle in mboxen gespeichert. Jetzt versuche ich mich gerade in einem Shellskript, um den Filter zu trainieren. Ich weiß, ich könnte einfach für jeden Ordner eine eigene Zeile schreiben, also in der Art: bogofilter -n -v < ~/Mail/.Linux.directory/SuSE-Linux Aber irgendwie ist das ja "uncool". So muß ich das Skript jedesmal anpassen, wenn ich meine Ordnerstruktur etwas verändere. Das muß doch auch "einfach" mit einem find gehen. Ich dachte da etwas in der Art: bogofilter -n -v < `find ~/Mail/ -"reg. Ausdruck" Ich habe zwar schon die Man-Page studiert, aber mich wohl zu blöd angestellt. Oder geht das mit find nicht? Mit dem Ausdruck bin ich mir auch nicht so ganz sicher. Mein erster Anlauf war: [^\.].* Also für jede Datei, die nicht mit einem Punkt beginnt. Dann muß aber noch irgendwie die File mit meinen gesammelten Spam-Mails ausgeschlossen werden: also irgendwie "und nicht Spam" - die Spam-Mails liegen in ~/Mail/Spam. Aber das mit dem reg. Ausdruck müßte ich ja durch ausprobieren schaffen, wenn ich find ersteinmal mit den Ausdrücken füttern könnte. Ich denke, für alte "Shell-Hasen" dürfte das doch kein Problem sein, oder? Auf jeden Fall, vielen Danke für die Hilfe. Gruß Thilo
Hallo Thilo, Thilo A. Coblenzer schrieb:
Ich habe zwar schon die Man-Page studiert, aber mich wohl zu blöd angestellt. Oder geht das mit find nicht? Mit dem Ausdruck bin ich mir auch nicht so ganz sicher. Mein erster Anlauf war: [^\.].* Also für jede Datei, die nicht mit einem Punkt beginnt. Dann muß aber noch irgendwie die File mit meinen gesammelten Spam-Mails ausgeschlossen werden: also irgendwie "und nicht Spam" - die Spam-Mails liegen in ~/Mail/Spam.
Also alle Dateien unterhalb von ~/Mail, die nicht mit einem Punkt beginnen und nicht mit "Spam" beginnen? find ~/Mail -type f -name "?*" -a ! -name "Spam*" -print Da braucht man noch nichtmal REs für, das geht mit shell patterns Gruß christian
Christian Schult <cschult@gmx.de> [Sa, 17 Jan 2004 14:52:02 +0100]:
find ~/Mail -type f -name "?*" -a ! -name "Spam*" -print
Das reicht nur, wenn die Shell im aktuellen Verzeichnis nichts findet, das auf die Suchmuster passt, denn "" verhindert keine Expansion durch die Shell! Um sicher zu gehen, sollte *immer* '' verwendet werden oder mit \ geschützt werden, also entweder find ~/Mail -type f -name '?*' -a ! -name 'Spam*' -print oder find ~/Mail -type f -name \?\* -a ! -name Spam\* -print Dann funktioniert es auch mit Sicherheit :) Philipp
Hi, Philipp Thomas wrote:
Das reicht nur, wenn die Shell im aktuellen Verzeichnis nichts findet, das auf die Suchmuster passt, denn "" verhindert keine Expansion durch die Shell!
Also bei mir macht es einen Unterschied, ob ich echo * oder echo "*" eingebe. Ich leite großzügig daraus ab, dass " " Shell Expansion von *, ? usw. unterbindet. Oder? Ré -- Registered Linux User #324404
René Matthäi <matthaei@gmx.de> [Sa, 17 Jan 2004 17:21:14 +0100]:
Ich leite großzügig daraus ab, dass " " Shell Expansion von *, ? usw. unterbindet. Oder?
Verf*, du hast Recht :) Ich habe mal wieder Suchmuster für Dateien mit Shellvariablen und anderen Zeichen, die die Shell interpretiert, verwechselt. echo "$PWD" und echo '$PWD' haben sehr unterschiedliche Ergebnisse. Philipp
Christian Schult <cschult@gmx.de> [Sa, 17 Jan 2004 14:52:02 +0100]: Um sicher zu gehen, sollte *immer* '' verwendet werden oder mit \ geschützt werden, also entweder
find ~/Mail -type f -name '?*' -a ! -name 'Spam*' -print oder find ~/Mail -type f -name \?\* -a ! -name Spam\* -print Euch Zwei vielen Dank für die Hilfe! Mit shell patterns kenne ich mich gar nicht aus. Daher muß ich sagen, daß mir der Ausdruck ein Buch mit sieben Siegeln ist. OK, ich sehe ein das "-a" ein logisches "und" ist und "!" die Negierung. Das "Spam*" verstehe ich auch noch. Aber was das "?*" mit den Punkt-Files zu tun hat, finde ich nicht so intuitiv. Aber na ja - auf jeden Fall zeigt mir find nun die gewünschten Dateien an. Leider bin ich immernoch nicht so ganz am Ziel. Das Problem ist wohl, daß ich jetzt eine ganz Liste von Dateien habe. Ich muß es irgendwie schaffen, Bogofilter nach und nach mit den Dateien zu füttern. Im Moment sieht es so aus:
Moin, Am Samstag, 17. Januar 2004 16:57 schrieb Philipp Thomas: thilo@vlinux:~$ bogofilter -n -v < `find ~/Mail/ -name Non*` # 8671 words, 31 messages Funktioniert also. Das find liefert allerdings auch nur eine Datei: thilo@vlinux:~$ find ~/Mail/ -name Non* /home/thilo/Mail/Non-Spam Wenn ich jetzt allerdings mehrere Dateien habe, funktioniert es nicht mehr: thilo@vlinux:~$ bogofilter -n -v < `find ~/Mail/ -name SuSE*` -bash: `find ~/Mail/ -name SuSE*`: ambiguous redirect thilo@vlinux:~$ find ~/Mail/ -name SuSE* /home/thilo/Mail/.Linux.directory/SuSE-Laptop /home/thilo/Mail/.Linux.directory/SuSE-Linux /home/thilo/Mail/.Linux.directory/SuSE-Multimedia /home/thilo/Mail/.Linux.directory/SuSE-Programming /home/thilo/Mail/.Linux.directory/SuSE-Talk Oder natrülich auch: thilo@vlinux:~$ bogofilter -n -v < `find ~/Mail -type f -name \?\* -a ! -name Spam\* -print` -bash: `find ~/Mail -type f -name \?\* -a ! -name Spam\* -print`: ambiguous redirect Wie kann ich dem denn jetzt noch begegnen? Gruß & Danke Thilo
Hallo Thilo, Thilo A. Coblenzer schrieb:
Euch Zwei vielen Dank für die Hilfe! Mit shell patterns kenne ich mich gar nicht aus. Daher muß ich sagen, daß mir der Ausdruck ein Buch mit sieben Siegeln ist.
Suche in "man bash" nach "Pattern Matching", den Suchbegriff kannst du nach drücken von / eingeben.
OK, ich sehe ein das "-a" ein logisches "und" ist und "!" die Negierung.
Richtig.
Das "Spam*" verstehe ich auch noch. Aber was das "?*" mit den Punkt-Files zu tun hat, finde ich nicht so intuitiv.
Aus "man find": [...] -name pattern Base of file name (the path with the leading directories removed) matches shell pat- tern pattern. The metacharacters (`*', `?', and `[]') do not match a `.' at the start of the base name. To ignore a directory and the files under it, use -prune; [...]
Aber na ja - auf jeden Fall zeigt mir find nun die gewünschten Dateien an. Leider bin ich immernoch nicht so ganz am Ziel. Das Problem ist wohl, daß ich jetzt eine ganz Liste von Dateien habe. Ich muß es irgendwie schaffen, Bogofilter nach und nach mit den Dateien zu füttern. Im Moment sieht es so aus: thilo@vlinux:~$ bogofilter -n -v < `find ~/Mail/ -name Non*` # 8671 words, 31 messages Funktioniert also. Das find liefert allerdings auch nur eine Datei: thilo@vlinux:~$ find ~/Mail/ -name Non* /home/thilo/Mail/Non-Spam Wenn ich jetzt allerdings mehrere Dateien habe, funktioniert es nicht mehr: thilo@vlinux:~$ bogofilter -n -v < `find ~/Mail/ -name SuSE*` -bash: `find ~/Mail/ -name SuSE*`: ambiguous redirect thilo@vlinux:~$ find ~/Mail/ -name SuSE* /home/thilo/Mail/.Linux.directory/SuSE-Laptop /home/thilo/Mail/.Linux.directory/SuSE-Linux /home/thilo/Mail/.Linux.directory/SuSE-Multimedia /home/thilo/Mail/.Linux.directory/SuSE-Programming /home/thilo/Mail/.Linux.directory/SuSE-Talk
Oder natrülich auch: thilo@vlinux:~$ bogofilter -n -v < `find ~/Mail -type f -name \?\* -a ! -name Spam\* -print` -bash: `find ~/Mail -type f -name \?\* -a ! -name Spam\* -print`: ambiguous redirect Wie kann ich dem denn jetzt noch begegnen?
Indem du bogofilter in einer Schleife mit einer Datei nach der anderen Aufrufst. Das geht sehr schön in der Shell: for element in `find ...`; do bogofilter -n -v < $element; done In die backticks musst du natürlich den kompletten find-Aufruf setzen. Gruß christian
Moin, Am Montag, 19. Januar 2004 00:07 schrieb Christian Schult:
Thilo A. Coblenzer schrieb:
Das Problem ist wohl, daß ich jetzt eine ganz Liste von Dateien habe. Ich muß es irgendwie schaffen, Bogofilter nach und nach mit den Dateien zu füttern. Indem du bogofilter in einer Schleife mit einer Datei nach der anderen Aufrufst. Das geht sehr schön in der Shell:
for element in `find ...`; do bogofilter -n -v < $element; done
In die backticks musst du natürlich den kompletten find-Aufruf setzen. cool vielen Dank! Jetzt funktioniert es so, wie ich mir das vorgestellt hatte!
Gruß Thilo
participants (4)
-
Christian Schult
-
Philipp Thomas
-
René Matthäi
-
Thilo A. Coblenzer