我有一个包含多个文件的文件夹:
W1747_RH_sig_window_outliers_g_chrom
W1747_RH_sig_window_outliers_g_pos
W1747_RH_sig_window_snps_g_chrom
W1747_RH_sig_window_snps_g_pos
W19173_RH_sig_window_outliers_g_chrom
W19173_RH_sig_window_outliers_g_pos
W1747_RH_sig_window_outliers_g_chrom
两者W1747_RH_sig_window_outliers_g_pos
都对应于单个文件W1747_RH_sig_window_outliers_g
,或者W1747_RH_sig_window_snps_g_chrom
两者W1747_RH_sig_window_snps_g_pos
都对应于W1747_RH_sig_window_snps
我想粘贴它们
paste W1747_RH_sig_window_outliers_g_chrom W1747_RH_sig_window_outliers_g_pos > W1747_RH_sig_window_outliers_vcf. txt
paste W1747_RH_sig_window_snps_g_chrom W1747_RH_sig_window_snps_g_pos > W1747_RH_sig_window_snps_vcf.txt
然而,由于有超过 200 个文件,我很难这样做,有没有更简单的方法来做到这一点,例如通过循环运行?
答案1
使用 POSIX shell:
for file in *_g_chrom; do
base=${file%_g_chrom}
paste -- "$file" "${base}_g_pos" > "${base}_vcf.txt"
done