I have a data file that I want to normalize using awk
, based on the last datapoint. Therefor, I would like to access the last data point first, to normalize the data, then process normally.
The following method, using tac
twice, does the job, but, is maybe more complicated than necessary.
$ cat file
0 5
1 2
2 3
3 4
$ tac file | awk 'NR==1{norm=$2} {print $1, $2/norm}' | tac
0 1.25
1 0.5
2 0.75
3 1
My question is the following: Is it possible to obtain the above result by using awk only?
I think the answer is "No, awk scans the file line by line", but I am open for suggestions for alternatives.