Linux 如何将列从一个文件粘贴到另一个临时文件?
我已经编辑了前面的问题,因为它太长太烦人了,现在我已经找到了我想要的东西,我看到下面代码中的一些操作中有一个小故障。寻求建议 我有代码,现在它可以正常工作,但我得到了一个额外的0行,我无法理解为什么?有什么建议吗 代码 输出Linux 如何将列从一个文件粘贴到另一个临时文件?,linux,bash,shell,awk,sed,Linux,Bash,Shell,Awk,Sed,我已经编辑了前面的问题,因为它太长太烦人了,现在我已经找到了我想要的东西,我看到下面代码中的一些操作中有一个小故障。寻求建议 我有代码,现在它可以正常工作,但我得到了一个额外的0行,我无法理解为什么?有什么建议吗 代码 输出 chr start end test_K27ac_S12818 test_K27ac_S12838 test_K27me3_S12815_5cols test_K27me3_S12830_5cols test_K4me1_S12816 test_
chr start end test_K27ac_S12818 test_K27ac_S12838 test_K27me3_S12815_5cols test_K27me3_S12830_5cols test_K4me1_S12816 test_K4me1_S12831 test_K4me1_S12836
chr1 754118 754696 0 0 0 0 290 576 0
chr1 804929 805633 0 0 704 0 277 0 704
chr1 826069 826438 0 0 0 0 369 0 0
chr1 839340 839608 0 0 268 0 268 0 0
chr1 840388 843628 0 0 3240 0 816 2434 923
chr1 845517 847768 0 0 2251 820 1113 2106 1677
chr1 850950 854146 0 0 3196 3196 2184 3196 1302
chr1 855361 857280 0 0 1919 0 1911 1919 979
chr1 857930 859278 0 0 1348 0 1139 1125 923
chr1 859906 860677 351 0 771 463 0 0 771
0
一切都很好,除了最后一行显示为0,不知道为什么??任何建议我相信我做的是正确的,所以我自己修改了代码,我就是这样做的
#!/bin/bash
#$ -S /bin/bash
cd /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test
cut -f 1,2,3 /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test_merge.bed > tmp
printf "chr\tstart\tend" > tsamples
for file in `ls *.bed`; do
printf "\t" >> tsamples
printf `basename $file .bed` >> tsamples
#echo $file | cut -d_ -f 1,2,3 >> tsamples
intersectBed -wao -a /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test_merge.bed -b $file -f 0.20 | cut -f 9 | tail -n+1 | paste tmp - > tmp2
mv tmp2 tmp
done
echo "" >> tsamples
cat tsamples tmp > histone_marks.map
rm tsamples tmp
sed '$d' histone_marks.map
这确实有效,但我知道这是一种非常粗糙的方法。我不明白为什么最后一行0会出现,但我相信它是用bash进行的某种操作,但不适用于intesectBed操作,因为列非常好。您的问题在于intersectBed之前的printf语句:删除printf语句中数字3后的逗号是的,我找到了,谢谢,但问题是输出没有标题,而且我希望输出有文件名的典型标题和输出文件的前3个字段合并,如我的输出mentioend如果您自己回答了这个问题,请考虑把答案张贴并接受,其实答案并不完全正确。我需要一些建议。我想出了一种方法来进行更改,但是我得到了一些额外的行,我不应该这样做。我怎样才能把我制作的全部代码和我得到的期望输出放在一起呢。Thanks@pcantalupo我编辑了我的查询,你能告诉我为什么最后一行是0吗?
#!/bin/bash
#$ -S /bin/bash
cd /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test
cut -f 1,2,3 /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test_merge.bed > tmp
printf "chr\tstart\tend" > tsamples
for file in `ls *.bed`; do
printf "\t" >> tsamples
printf `basename $file .bed` >> tsamples
#echo $file | cut -d_ -f 1,2,3 >> tsamples
intersectBed -wao -a /path/vdas/client/ChIP-Seq/output/merge_MACS2_peaks_patient_specific/EOC/test_merge.bed -b $file -f 0.20 | cut -f 9 | tail -n+1 | paste tmp - > tmp2
mv tmp2 tmp
done
echo "" >> tsamples
cat tsamples tmp > histone_marks.map
rm tsamples tmp
sed '$d' histone_marks.map