2023-04-30

Search and print result along with earlier information

I have total 30 test result files, each having 12 iterations in it. The structure of the file is as below:

File1_loc/result.txt

# starting information
# User information
# Time stamps
# Random infomration
# Thousnads of lines in between
# ----------------- Iteration 1 ----------------------
# $Test show addr 0x2341233  data 0x241341
# $Test matches Pass
# $Test show addr 0x123324  data 0x223245
# $Test matches Pass
# Few hundreds line
# $Test time: ERROR: Results_dont_Match Loc: Actual=31ABCDEF Expected=21ABCDE
# ******:time ns: CHANGE ERROR COUNT TO: 1
# $Test show addr 0x2341233  data 0x241341
# $Test matches Pass
# $Test show addr 0x123324  data 0x223245
# $Test matches Pass
# Few hundreds line
# ----------------------------------------------------
# ----------------- Iteration 2 ----------------------
# $Test show addr 0x2341233  data 0x241341
# $Test matches Pass
# $Test show addr 0x123324  data 0x223245
# $Test matches Pass
# Few hundreds line
# $Test time: ERROR: Results_dont_Match Loc: Actual=31ABCDEF Expected=21ABCDE
# ******:time ns: CHANGE ERROR COUNT TO: 2
# $Test show addr 0x2341233  data 0x241341
# $Test matches Pass
# $Test show addr 0x123324  data 0x223245
# $Test matches Pass
# Few hundreds line
# $Test time: ERROR: Results_dont_Match Loc: Actual=EF12321 Expected=DL298234
# ******:time ns: CHANGE ERROR COUNT TO: 3
# ----------------------------------------------------
This pattern continues
# ----------------- Iteration 12 ----------------------
# $Test show addr 0x2341233  data 0x241341
# $Test matches Pass
# $Test show addr 0x123324  data 0x223245
# $Test matches Pass
# Few hundreds line
# $Test time: ERROR: Results_dont_Match Loc: Actual=31ABCDEF Expected=21ABCDE
# ******:time ns: CHANGE ERROR COUNT TO: 4
# $Test show addr 0x2341233  data 0x241341
# $Test matches Pass
# $Test show addr 0x123324  data 0x223245
# $Test matches Pass
# Few hundreds line
# ----------------------------------------------------

I do have total 30 files like this. The file contains results and ERROR, if mismatch. I am interested to print the following information for each result.txt file.

    File1_Summary:
    # ----------------- Iteration 1 ----------------------
    # $Test time: ERROR: Results_dont_Match Loc: Actual=31ABCDEF Expected=21ABCDE
    # ******:time ns: CHANGE ERROR COUNT TO: 1
    # ----------------- Iteration 2 ----------------------
    # $Test time: ERROR: Results_dont_Match Loc: Actual=31ABCDEF Expected=21ABCDE
    # ******:time ns: CHANGE ERROR COUNT TO: 2
    # $Test time: ERROR: Results_dont_Match Loc: Actual=EF12321 Expected=DL298234
    # ******:time ns: CHANGE ERROR COUNT TO: 3
    # ----------------- Iteration 12 ----------------------
    # $Test time: ERROR: Results_dont_Match Loc: Actual=31ABCDEF Expected=21ABCDE
    # ******:time ns: CHANGE ERROR COUNT TO: 4
    File2_Summary:
    # ----------------- Iteration 1 ----------------------
    # $Test time: ERROR: Results_dont_Match Loc: Actual=31ABCDEF Expected=21ABCDE
    # ******:time ns: CHANGE ERROR COUNT TO: 1
    # ----------------- Iteration 12 ----------------------
    # $Test time: ERROR: Results_dont_Match Loc: Actual=31ABCDEF Expected=21ABCDE
    # ******:time ns: CHANGE ERROR COUNT TO: 2

I have used awk and search for the 4th field matching ERROR, which prints out the lines. However, I would like to also print out the Iteration # information.

awk '$4 ~/ERROR/' File1_loc/result.txt


No comments:

Post a Comment