How can I print the filename and the result of 1/2*(a+b), where a is the 1st field of the 2nd line and b is the 1st field of the last line please? I do not know how to save the values into variables as constants. Many thanks
awk -v a=$(NR==2{print $1}) b=$(END(print $1)) '{print FILENAME, 1/2*(a+b)}' rv*.out
file1
4 5 6
14545.5886 2 6
2 3 5
45457.5462 8 6
file2
1 2
34441.4545 8
6 8
8 8
54447.4545 1
Output for:
for file in test1.txt test2.txt; do
awk ' (NR==2){a=$1} END{print FILENAME, 1/2*(a+$1)}' "$file" >> stredni.txt;
done
test1.txt 7272.79
test2.txt 17220.7
Desired result:
test1 30001.5674
test2 44444.4545