I have around 1000 files in a directory (file1.txt, file2.txt, ... file1000.txt), each file is 2 columns, the first colums are same for all of them, second one is different.
file1.txt
1 10
2 20
3 30
4 40
5 50
file2.txt
1 100
2 400
3 500
4 600
5 900
what I need is , I want output.txt such as for only 2 above files, it will give
output.txt
1 110
2 420
3 530
4 640
5 950
well if there was only two files i could do
pr -m -t -s\ *txt | gawk '{print $1,$2+$4}'
but I have thousand files , I need sth like
pr -m -t -s\ *txt | gawk '{print $1,$2+$4+...+$2000}'
also I want to make it dynamic (number of files may change)
what I tried is
#!/bin/bash
numfiles=$(ls *.txt | wc -l)
command=""
for (( c=1; c<=$numfiles; c++ ))
do
command=" ${command}\$$[2*${c}]+"
pr -m -t -s\ *trace | gawk '{print $1,${command}}'
done