If I have several files like this:
filename1.txt
# 0.2
1.0 0.0
1.5 1.0
2.0 0.8
2.5 1.1
filename2.txt
# 0.5
1.0 0.1
1.5 0.6
2.0 1.3
2.5 0.4
where all of their first columns are the same. I just need the output, for example:
# 0.7
1.0 0.1
1.5 1.6
2.0 2.1
2.5 1.5
I know that
paste filename1.txt filename2.txt | awk '{print $1, $2+$4}'
works, but this is not possible if there are more than 20 files. I also tried using
awk 'NR==FNR{a[NR]=$2;next}{print $1,$2+a[FNR]}' filename1.txt filename2.txt
but it only works with two files and then ignores the rest.
source
share