Bash script that analyzes report files

前端 未结 3 2013
伪装坚强ぢ
伪装坚强ぢ 2021-01-22 08:54

I have the following bash script which I will use to analyze all report files in the current directory:

#!/bin/bash    


# methods
analyzeStructuralErrors()
{ 
         


        
3条回答
  •  情话喂你
    2021-01-22 09:12

    Below is a working awk implementation that uses it's pseudo multidimensional arrays. I've included sample output to show you how it looks. I took the liberty to add a 'Count' column to denote how many times a certain "Issue" was hit for a given Error Code

    #!/bin/bash
    
    awk '
     /Error Code for Issue/ {
       errCode[currCode=$5]=$5
     }
     /^ +[0-9-]+$/ {
       split($0, tmpArr, "-")
       error[errCode[currCode],tmpArr[1]]++
     }
     END {
       for (code in errCode) {
         printf("Error Code: %s\n", code)
         for (item in error) {
           split(item, subscr, SUBSEP)
           if (subscr[1] == code) {
             printf("\tIssue: %s\tCount: %s\n", subscr[2], error[item])
           }
         }
       }
     }
    ' *_report*.txt
    

    Output

    $ ./report.awk
    Error Code: B
            Issue:    1212  Count: 3
    Error Code: X
            Issue:    2211  Count: 1
            Issue:    1143  Count: 2
    Error Code: Y
            Issue:    2961  Count: 1
            Issue:    6666  Count: 1
            Issue:    5555  Count: 2
            Issue:    5911  Count: 1
            Issue:    4949  Count: 1
    Error Code: Z
            Issue:    2222  Count: 1
            Issue:    1111  Count: 1
            Issue:    2323  Count: 2
            Issue:    3333  Count: 1
            Issue:    1212  Count: 1
    

提交回复
热议问题