ディレクトリ内の複数のテストファイルの平均値を$2
として計算し、出力ファイルをtab-delimeted
出力ファイルにマージしようとしています。出力ファイルは、pref
で抽出されたファイル名が$1
であり、$2" is the calculated average with one decimal, rounded up. There is also a header in the output
サンプルin
$ 1 and
パーセントin
$ 2という2つのフィールドです。以下は近似しているようですが、出力にヘッダーを追加し、1つのタブ区切りファイルに結合し、小数点以下3桁まで四捨五入しています)、希望の出力を得られない方法がわかりません。ありがとうございました :)。 複数のテキストファイルのフィールドの平均を計算して1つにマージする
AASS 99.81
ABAT 100.00
ABCA10 0.0
456_base
123_base.txt。TXT
ABL2 97.81
ABO 100.00
ACACA 99.82
所望の出力(タブdelimeted)
Sample Percent
123 66.6
456 99.2
バッシュ
for f in /home/cmccabe/Desktop/20x/percent/*.txt ; do
bname=$(basename $f)
pref=${bname%%_base_*.txt}
awk -v OFS='\t' '{ sum += $2 } END { if (NR > 0) print sum/NR }' $f /home/cmccabe/Desktop/NGS/bed/bedtools/IDP_total_target_length_by_panel/IDP_unix_trim_total_target_length.bed > /home/cmccabe/Desktop/20x/coverage/${pref}_average.txt
done
? – Sundeep
それは大丈夫でしょう。ありがとうございました :)。 – Chris
@glenn jackmanはディレクトリ( '/ home/cmccabe/Desktop/20x/percent/*。txt')内の100個の' .txt'ファイルをそれぞれ一度に参照せずに一度に使用できますか?ありがとうございました :)。 – Chris