python - Rewrite config file based on standard error output -
python - Rewrite config file based on standard error output -
i'm new linux , have fedora 20 build class. installed tripwire using default, out of box configs , want take standard errors install prepare config file.
to collect errors:
tripwire -m -c tw.cfg 2> errors to clean error file processing:
cat errors.txt | grep "/" | cutting -d " " -f 3 > fixederrors this gives me nice clean file 1 path per line i.e.:
/bin/ash /bin/ash.static /root/.xresourcesi automate process comparing info in fixederrors config file , prepend matching strings '#'.
i tried sed, commented out whole config file!
sed 's/^/#/g' fixederrors > commentederrors alternatively, thought comparing config file , fixederrors , creating 3rd file. there way take 2 files, compare them, , remove duplicated data?
any help appreciated. tried bash , python, don't know plenty , went downwards rabbit hole on one. again, growth , not in production environment.
let's suppose have input file named fixederrors "clean"
/bin/ash /bin/ash.static /root/.xresources this input configuration file named config.original
use /bin/ash utilize /bin/bash stuff /bin/ash.static , friends /root/.xresources other stuff... with script in bash
#!/bin/bash input_conf_file="config.original" # original configuration file output_conf_file="config.new" # new configuration file input_error_file="fixederrors" # file of cleaned error rm -f $output_conf_file # let's create new file erasing old while read -r line ; # meanwhile there line in config file addingchar="" # no char add together # while ifs= read -r line2 ; # each line of error file, # here can add together specific rules match e.g # line2=${line2}" " # if has space after... [[ $line == *$line2* ]] && addingchar="#" # if found --> alter prefix "#" done < $input_error_file echo "${addingchar}${line}" >> $output_conf_file # print in new file done < $input_conf_file cat $output_conf_file # can avoid it's check results exit 0 you have output
#use /bin/ash utilize /bin/bash #do stuff /bin/ash.static , friends #/root/.xresources other stuff... note:
ifs= removes trailing spaces in read use wisely because e.g. match /bin/ash grab lines /bin/ash.everything; if exists line in configuration input file /bin/ash.dynamic commented too. without prior knowledge of configuration file it's not possible set specific rule, can starting here. python bash sed
Comments
Post a Comment