I am running a bash script that looks through error logs and produces a report that prints in a Mac Terminal.
Currently, the output looks like this:
This error report is derived from Command Logs from ________ to __________.
IP addresses:
109.xx.xxx.xxx
Error Codes List:
(code 12)
(code 30)
Common Errors - Count:
Code 2:
Code 10:
Code 11:
Code 12: 237
Code 14:
Code 20:
Code 23:
Code 30: 5
Code 35:
Code 37:
Code 52:
/usr/local/bin/backerr: line 45: `$skipping': not a valid identifier
Total: 242
Total Files Transferred:
3558
Count complete.
The following are details for each error:
// all of the 242 above-referenced lines //
Skipped files:
// lists all of the lines that have the word 'skipping\ ' //
As you can see, I do not have the correct identifier:
/usr/local/bin/backerr: line 45: `$skipping': not a valid identifier
This is the code I have to detect the lines with 'skipping\ ' in them, count the total, and print the total under the Code XX: total above. Also, I want the 'skipping\ ' total to add to 'Total: 242'.
count=()
total=0
while read skipping; do
(( count[$skipping]++, total++ ))
done < <(grep 'skipping\ ' $input_variable)
for $skipping in $input_variable; do
echo "Skipped: ${count[$skipping]}"
done
My expected output of the "Common Errors - Count:" section should be as follows:
Common Errors - Count:
Code 2:
Code 10:
Code 11:
Code 12: 237
Code 14:
Code 20:
Code 23:
Code 30: 5
Code 35:
Code 37:
Code 52:
Skipped: 107 (I made up this number for this question)
Total: 349
I am stuck here. Please help.
As a work-around, instead of using the code below:
while read skipping; do
(( count[$skipping]++, total++ ))
done < <(grep 'skipping\ ' $input_variable)
for $skipping in $input_variable; do
echo "Skipped: ${count[$skipping]}"
done
I replaced that with:
echo "Total Skipped Files: " ; egrep -c 'skipping' $input_variable ;
But, this does not really produce the ideal outcome as I originally envisioned.
< <and why not<107and349numbers from above input?