mercredi 22 septembre 2021

If an awk IF is met, do another awk

Very new to awk and bash. I am trying to complete an analysis on a log file. The file contains a time value, that I would like give a min and max value for, but I need to complete this only for a specific url string that is found in the log.

Below is an example of the data:

[rootawk]# cat testdata.txt
123 192.168.1.1 edge 20 /url/test/1
123 192.168.1.1 edge 10 /url/test/1
123 192.168.1.1 edge 30 /url/test/1
123 192.168.1.1 google 70 /url/test/3
124 192.168.1.1 edge 25 /url/test/3
124 192.168.1.1 google 15 /url/test/3

I can run and awk command of the testdata.txt that only selects certain criteria:

awk '{if ($1 == 123 && $5 == "/url/test/1") {print $1,$2,$3,$4,$5 }}' testdata.txt

I can also run a Min Max awk to give me the min Max of the testdata.txt (part2)

awk '(NR==1){Min=$4;Max=$4};(NR>=2){if(Min>$4) Min=$4;if(Max<$4) Max=$4} END {printf "The Min is %d ,Max is %d",Min,Max}' testdata.txt

However, I would like to be able to do is run the MinMax (part2) on the output of the search criteria (Part1).

So The response would be in this case:

Number of /url/test/1 = 3 with a Time; Min: 10 Max:30

I am not sure how best to approach this.

I found this link, but it is not clear how I run this against a logfile. (this will be set to $1 in bash script)

Execute another awk from awk file

TIA

Aucun commentaire:

Enregistrer un commentaire