Timeline for grep dynamically multiple files with customized output
Current License: CC BY-SA 3.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 17, 2017 at 13:27 | comment | added | achille | (I also tried with GREP_COLOR, which is deprecated but still supported in my grep version). | |
| Aug 17, 2017 at 13:26 | comment | added | achille | @ Brett <br/ > tail -f /var/log/auth.log | GREP_COLOR='01;34' egrep -i --color=always '^.*failed.*$|^.*opened.*$' -> works fine <br/ > tail -f /var/log/syslog | GREP_COLOR='01;31' egrep -i --color=always '^.*kvm.*$' -> works fine <br/ > tail -f /var/log/{auth.log,syslog} | GREP_COLOR='01;34' egrep -i --color=always '^.*failed.*$|^.*opened.*$' | GREP_COLOR='01;31' egrep -i --color=always '^.*kvm.*$' -> no output at all. <br/ > tail -f /var/log/{auth.log,syslog} | GREP_COLORS='01;34' grep --color=always '(FAILED\|opened)' | GREP_COLORS='01;31' grep --color=always '(KVM\|kvm)' -> no output. | |
| Aug 17, 2017 at 13:23 | comment | added | achille | @Hauke <br/> tail -n 0 -f /var/log/syslog | awk -v searchSyslog="kvm|KVM" '/^==> \/var\/log\/syslog <==$/ {print "\033[0;31m"; pattern=searchSyslog }; $0 ~ pattern' ---> it prints all syslog so it works. <br/> tail -n 0 -f /var/log/auth.log | awk -v searchAuth="FAILED|opened" '/^==> \/var\/log\/auth.log <==$/ {print "\033[0;34m"; pattern=searchAuth }; $0 ~ pattern' ---> then I purposely fail root authentication (in order to have 'FAILED' pattern in /var/log/auth.log, the snippet outputs nothing. Now if I simply do a tail -f /var/log/auth.log | grep FAILED, it works. So I am stuck | |
| Aug 17, 2017 at 13:22 | comment | added | achille | @Hauke <br/> tail -n 0 -f /var/log/syslog /var/log/auth.log | awk -v searchSyslog="kvm|KVM" -v searchAuth="FAILED|open" '/^==> \/var\/log\/syslog <==$/ {print "\033[0;31m"; pattern=searchSyslog }; /^==> \/var\/log\/auth.log <==$/ { print "\033[0;34m"; pattern=searchAuth }; $0 ~ pattern' -> prints only syslog. <br/> | |
| Aug 16, 2017 at 21:10 | history | edited | Brett Levene | CC BY-SA 3.0 | added 136 characters in body |
| Aug 16, 2017 at 20:55 | history | edited | Brett Levene | CC BY-SA 3.0 | added 103 characters in body; deleted 2 characters in body; deleted 1 character in body; added 1 character in body |
| Aug 16, 2017 at 20:46 | history | answered | Brett Levene | CC BY-SA 3.0 |