0

I've pulled the highest count of a particular field (AsicErr) from a file, and filtered it as below:

grep AsicErr file.txt | sort -t: -k2nr | head
EGQ0 AsicErr             :         3464363
EGQ0 AsicErr             :         12312
EGQ0 AsicErr             :         120

Based on this, I would like to further filter this file to pull the lines which have arrows next to them as per below:

Sample file structure

RP/0/RP0/CPU0:abc#show controllers fia statistics instance 0 location 0/0/CPU0  <<<<<<<<<<<<<<<
  Tue Jun  4 11:00:07.521 UTC
  Node ID: 0/0/CPU0
  FIA Statistics Rack: 0, Slot: 0, Asic instance: 0  <<<<<<<<<<<<<<<
  Total number of blocks: 12
  Per Block Statistics:
  EGQ counters:
  EGQ0 CnmCntDrops                     :                0
  EGQ0 CnmCntFlowControl               :                0
  EGQ0 CnmPktsCnt                      :                0
  EGQ0 AsicErr                         :         3464363    <<<<<<<<<<<<<<<
  EGQ0 CntProfileOffset1               :                0
  EGQ0 CntProfileOffset2               :                0
  EGQ0 CntProfileOffset3               :                0
  EGQ0 CntProfileOffset4               :                0
  EGQ0 CntProfileOffset5               :                0
  EGQ0 CrcErrFabricCnt                 :                0
  EGQ0 CrcErrOthersCnt                 :                0

  RP/0/RP0/CPU0:abc#show controllers fia statistics instance 3 location 0/0/CPU0   <<<<<<<<<<<<<<<
  Tue Jun  4 11:00:11.215 UTC
  Node ID: 0/0/CPU0
  FIA Statistics Rack: 0, Slot: 0, Asic instance: 3   <<<<<<<<<<<<<<<
  Total number of blocks: 12
  Per Block Statistics:
  EGQ counters:
  EGQ0 CnmCntDrops                     :                0
  EGQ0 CnmCntFlowControl               :                0
  EGQ0 CnmPktsCnt                      :                0
  EGQ0 AsicErr                         :         12312     <<<<<<<<<<<<<<<
  EGQ0 CntProfileOffset1               :                0
  EGQ0 CntProfileOffset2               :                0
  EGQ0 CntProfileOffset3               :                0
  EGQ0 CntProfileOffset4               :                0
  EGQ0 CntProfileOffset5               :                0
  EGQ0 CrcErrFabricCnt                 :                0
  EGQ0 CrcErrOthersCnt                 :                0

 RP/0/RP0/CPU0:abe#show controllers fia statistics instance 1 location 0/0/CPU0   <<<<<<<<<<<<<<<
 Tue Jun  4 11:00:32.283 UTC
 Node ID: 0/0/CPU0
 FIA Statistics Rack: 0, Slot: 0, Asic instance: 1    <<<<<<<<<<<<<<<
 Total number of blocks: 12
 Per Block Statistics:
 EGQ counters:
 EGQ0 CnmCntDrops                     :                0
 EGQ0 CnmCntFlowControl               :                0
 EGQ0 CnmPktsCnt                      :                0
 EGQ0 AsicErr                         :         120   <<<<<<<<<<<<<<<
 EGQ0 CntProfileOffset1               :                0
 EGQ0 CntProfileOffset2               :                0
 EGQ0 CntProfileOffset3               :                0
 EGQ0 CntProfileOffset4               :                0
 EGQ0 CntProfileOffset5               :                0
 EGQ0 CrcErrFabricCnt                 :                0
 EGQ0 CrcErrOthersCnt                 :                0
 EGQ0 CupErrFabricCnt                 :                0

Desired output:

 RP/0/RP0/CPU0:abc#show controllers fia statistics instance 0 location 0/0/CPU0  
  FIA Statistics Rack: 0, Slot: 0, Asic instance: 0  
  EGQ0 AsicErr                         :         3464363   
  RP/0/RP0/CPU0:abc#show controllers fia statistics instance 3 location 0/0/CPU0   
  FIA Statistics Rack: 0, Slot: 0, Asic instance: 3   
  EGQ0 AsicErr                         :         12312   
 RP/0/RP0/CPU0:abe#show controllers fia statistics instance 1 location 0/0/CPU0   
 FIA Statistics Rack: 0, Slot: 0, Asic instance: 1    
 EGQ0 AsicErr                         :         20   

This would probably involve searching for the numerical value of the error, then reverse searching to get the FIA Statistics line, followed by reverse searching the show command to capture hostname of the device which is facing the issue.

If I could get some guidance on how to approach this it would be appreciated.

Thanks.

user
  • 493
  • 6
  • 13

1 Answers1

0

here is a standard Linux awk script:

awk '/AsicDropErr/{print $4}' file1 file2 |sort |head

You can put as many files in the awk command.

Dudi Boy
  • 4,551
  • 1
  • 15
  • 30
  • This doesn't appear to attempt to solve the problem stated in the question. The OP seems to want to perform a join between two files based on the error count (which seems rather error-prone anyway, but that's beside the point here). – tripleee Jun 09 '19 at 09:11
  • I believe I understood the question, reading multiple files. I hope @tripleee understand that a single `awk` script can handle many files in single sweep. – Dudi Boy Jun 09 '19 at 09:23
  • Absolutely; see the proposed duplicate for how I interpret this question. – tripleee Jun 09 '19 at 11:24