#!/bin/bash filename="PDOS_"$1 shift 1 # get filenames to sum: $str str=$@ #filename="$1" #"dos."$(echo $str | sed 's/ /./g') #echo " " echo getting PDOS file: $filename echo " " # get firt dos filename $str1, and the others $strs str1=$(echo $str | awk '{print $1}') # firt file name nc=$(head -n 1 $str1 | awk '{print NF}') # columes of dos file nr=$(wc -l $str1 | awk '{print $1}') # rows of dos file nf=$(echo $str | wc -w) # numbers of dos to sum paste $str > dos.tmpall # sum dos sed -n '1 p' $str1 > dos.tmpt # dos file title cat dos.tmpall | awk '{ if (NR==1) {} else { printf "%8.4f", $1; for (i=2;i<='$nc';i++) { a=0; for (j=1;j<='$nf';j++) { a=a+$((j-1)*'$nc'+i); } printf "%13.4e", a; } printf "\n"; } }' > dos.tmp cat dos.tmpt dos.tmp > $filename rm -rf dos.tmp*