Advertisement
Guest User

Untitled

a guest
Nov 9th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 1.63 KB | None | 0 0
  1. #!/bin/awk -f
  2.  
  3. BEGIN{
  4.     newCommandName = ""
  5.     lastCommandName = ""
  6.     firstTag = 1
  7.     firstMetric = 1
  8. }
  9.  
  10. function red(s) {
  11.     printf "\033[1;31m" s "\033[0m "
  12. }
  13.  
  14. function green(s) {
  15.     printf "\033[1;32m" s "\033[0m "
  16. }
  17.  
  18. function blue(s) {
  19.     printf "\033[1;34m" s "\033[0m "
  20. }
  21.  
  22.  
  23. /^Command: .+ output: Map/{
  24.    
  25.     if(firstTag == 1){
  26.         print(blue("============================ Tags found ============================"))
  27.         firstTag = 0
  28.     }
  29.    
  30.     commandName = $2
  31.    
  32.     gsub(/'+/, "", commandName)
  33.    
  34.     split($0, tagArray, "(")
  35.     split(tagArray[2], tagArray, ")")
  36.    
  37.     if(tagArray[1] != ""){
  38.        
  39.         print(red(commandName))
  40.         split(tagArray[1], tagArray, ", ")
  41.        
  42.         for(i in tagArray){
  43.             print(tagArray[i])
  44.         }
  45.        
  46.         print("\r")
  47.     }
  48. }
  49.  
  50. /INFO -- Command: '/{
  51.    
  52.     if(firstMetric == 1){
  53.         firstMetric = 0
  54.     } else {
  55.         print(red("\nCount per metric:"))
  56.     }
  57.     for(metric in foundMetrics){
  58.         print metric " had " foundMetrics[metric] " results"
  59.     }
  60.    
  61.     delete foundMetrics
  62.    
  63.     print("")  
  64.     commandName = $NF
  65.    
  66. }
  67.  
  68. /INFO -- Found [0-9]+ metrics:/{
  69.    
  70.     metricsFound = $4
  71.    
  72.     gsub(/[[\r']+/, "", commandName)
  73.    
  74.     print(green("================================== indeni script: " commandName " ==================================\n"))
  75.     print(red("Total results:\n") metricsFound "\n")
  76.     print(red("Metric examples:"))
  77. }
  78.  
  79. /Metric Name/{
  80.  
  81.     sub(/^INFO -- Metric Name: /, "", $0)
  82.    
  83.     if($1 in foundMetrics){
  84.         newMetric = 0
  85.         foundMetrics[$1] = foundMetrics[$1] + 1
  86.     } else {
  87.         newMetric = 1
  88.        
  89.         print($0)
  90.         foundMetrics[$1] = 1
  91.     }
  92. }
  93.  
  94. /^[ \}]+/{
  95.     if(newMetric == 1){
  96.         if(!(match($0, /^[:]+/))){
  97.             print($0)
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement