Usefull Python Scripts

Remove lines from File containing: bad_words

import sys
bad_words = [‚one bad word‘,‘ another bad word‘]
scriptname = sys.argv[0]
for _old in sys.argv:
if _old == scriptname:
continue
_new = _old + ‚_filter_x.log‘
print(„processing ‚“ + _old + „‚\n\noutput: “ + _new + „\n\n\n\n“)
with open(_old) as oldfile, open(_new, ‚w‘) as newfile:
for line in oldfile:
if any(bad_word in line for bad_word in bad_words):
newfile.write(line)

Combine draged Files

import sys
scriptname = sys.argv[0]
output_file = ‚kombination_x.log‘
with open(output_file, ‚w‘) as outfile:
for _old in sys.argv:
if _old == scriptname:
continue
print(„processing ‚“ + _old + „‚\n\noutput: “ + output_file + „\n\n\n\n“)
with open(_old) as infile:
for line in infile:
outfile.write(line)

Combine lines containing the good_words in a new file

import sys
good_words = [‚good word‘,’other good word‘]
scriptname = sys.argv[0]
for _old in sys.argv:
if _old == scriptname:
continue
_new = _old + ‚_filter_x.log‘
print(„processing ‚“ + _old + „‚\n\noutput: “ + _new + „\n\n\n\n“)
with open(_old) as oldfile, open(_new, ‚w‘) as newfile:
for line in oldfile:
if any(good_word in line for good_word in good_words):
newfile.write(line)

 

Create a Webserver in the Current Directory

python -m http.server

Schreibe einen Kommentar