Need expertise on awk

Hi everyone. I need some help on how to fix this.

I am getting positive result using the log file below and this command

awk -v t="06:10:22.211" -F'|' -v main=" RBL: " -v trig="BIOS-INFO" '$2 ~ t && $7 ~ main { first = $0; getline; } first && $7 ~ trig { printf "%s\n", first; exit }' log
|06:10:22.211| mymachine |2|     | kernel :|            RBL: RBL Code 10
|06:10:22.211| mymachine |1|     | kernel :|            DRPD: DRPD 789123
|06:10:22.211| mymachine |2|     | kernel :|            RTR: RTR Incomplete
|06:10:22.211| mymachine |2|     | kernel :|RunThread() - This is it BIOS-INFOXXX : Alert, get info on the upper part.

but with this log im getting negative results.

|06:10:22.201| mymachine |2|     | kernel :|            RBL: RBL Code 10
|06:10:22.201| mymachine |1|     | kernel :|            DRPD: DRPD 789123
|06:10:22.201| mymachine |2|     | kernel :|            RTR: RTR Incomplete
|06:10:22.211| mymachine |2|     | kernel :|RunThread() - This is it BIOS-INFOXXX : Alert, get info on the upper part. 

How can i fix the script to match the timestamp "06:10:22.211" first then get the trigger value even though the timestamp different?

thanks in advance.

Your 2nd log file and pattern does not match! What is it that you really want?

--ahamed

Try like..

awk -v t="06:10:22.2[01][01]" ...

Hi Ahamed101,

Yes that is right, 2nd log file and pattern doesn't match but the 2nd log file is supposed to be what I really want to match and achieve.

How should I get results based on the 2nd log?

thanks.

May be this is what you want.

awk -v t="06:10:22.211" -F'|' -v main=" RBL: " -v trig="BIOS-INFO" '$7 ~ main { first = $0 } $2 ~ t && $7 ~ trig { printf "%s\n", first; exit }' log

If not, please explain it once more.

--ahamed

1 Like

Hi Ahamed, this one works for me. thanks a lot.