The goal is to get output as below, containing file name and error count for each file.
/var/log/file2.log:5
/var/log/file3.log:7
/var/log/file5.log:3
/var/log/file7.log:2
Assuming there are many log files named "*.log" and all are in same format as below.
2021-03-16 01:01:01.001 ERROR 1234 --- [main] com.example.ClassAAAA : real error
2021-03-16 01:01:01.001 INFO 1234 --- [main] com.example.ClassAAAA : message
2021-03-16 01:01:01.001 ERROR 1234 --- [main] com.example.LibBB : real error
2021-03-16 01:01:01.001 INFO 1234 --- [main] com.example.LibBB : message
2021-03-16 01:01:01.001 ERROR 1234 --- [main] com.example.ClassCCCCCC : real error
2021-03-16 01:01:01.001 ERROR 1234 --- [main] com.example.ClassCCCCCC : real error
2021-03-16 01:01:01.001 INFO 1234 --- [main] com.example.ClassCCCCCC : message
2021-03-16 01:01:01.001 ERROR 1234 --- [main] com.example.ClassD : false alert
2021-03-16 01:01:01.001 INFO 1234 --- [main] com.example.ClassD : message
2021-03-16 01:01:01.001 ERROR 1234 --- [main] com.example.LibEEE : false alert
2021-03-16 01:01:01.001 INFO 1234 --- [main] com.example.LibEEE : message
2021-03-16 01:01:01.001 ERROR 1234 --- [main] com.example.LibFFFFF : false alert
2021-03-16 01:01:01.001 ERROR 1234 --- [main] com.example.LibFFFFF : false alert
2021-03-16 01:01:01.001 INFO 1234 --- [main] com.example.LibFFFFF : message
The major problem is that there are some known false alerts that shouldn't be counted.
For example, we hope to count errors logged by any class other than ClassD, LibEEE and LibFFFFF by below commmand.
grep -Pc '^.* ERROR .*((?<!(ClassD|LibEEE|LibFFFFF)).)*$' *.log | grep -v :0
But it doesn't work and below error is printed.
grep: lookbehind assertion is not fixed length
If it worked, the count would be 4 for above example log piece, logged by ClassAAAA, LibBB and ClassCCCCCC respectively.
UPDATE
Sincerely thank all of you for taking the time to share your idea. The reason I went into the think set of lookbehind is that I'd like to qualify the class name by "\s*:" initially, but the space and colon was missed eventually.
Though the goal can be achieved for now, just curious - is it possible to use lookbehind in this case?