What is the problem with all solutions using echo text >> file ? You can check with strace that at each such stage, file opened, then placed at the end, then text written and the file is closed. So if 1000 times echo text >> file , then there will be 1000 open , lseek , write , close . The number of open , lseek and close can be significantly reduced as follows:
while read key val; do case $key in banned-phrase) echo $val>&2;; banned-site) echo $val;; esac done >bannedsitelist 2>bannedphraselist <dansguardian-config
Stdout and stderr are redirected to files and remain open while the loop is alive. Thus, files are opened once and closed once. No need for lseek. In addition, file caching is used more, because unnecessary close calls will not buffer buffers each time.
Truey source share