简体   繁体   English

循环并打印和求和列 linux

[英]Loop through and print and sum columns linux

I want to go through 22 data sets labeled the same by chr1- chr22.我想通过 chr1-chr22 标记为相同的 22 个数据集 go。 This is what one file looks like.这是一个文件的样子。 als.sumstats.meta.chr10.txt.gz. als.sumstats.meta.chr10.txt.gz。 I want to unzip these files and extract all data from columns $2,$1,$3,$9 and in a new column sum $14 and $15.我想解压缩这些文件,并从列 $2、$1、$3、$9 和新列总和 $14 和 $15 中提取所有数据。 I want to then zip these files up when I am done.然后我想在完成后将这些文件 zip 起来。 I want to return an appended table with all data from each of the above columns for downstream analysis.我想返回一个附加表,其中包含来自上述每一列的所有数据以进行下游分析。 This is what I have and am having trouble with the zipping/unzipping part.这就是我在压缩/解压缩部分遇到的问题。

#!/bin/bash

FILES=/ALSsummaryGWAS/Summary_Statistics_GWAS_2016/als.sumstats.meta.chr{1..22}.txt.gz
for f in $FILES;
do
  echo "$FILES"
  echo "extracting columns 2,1,3,9"
  awk '{print $2,$1,$3,$9, $14+$15}' > ALSGWAS.txt
done
for f in $FILES; do
  gzip -d < $f | awk '{print $2,$1,$3,$9, $14+$15}' | tee -a all.txt | gzip > $f.sub
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM