首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将文件中的列粘贴到另一个临时文件中?

如何将文件中的列粘贴到另一个临时文件中?
EN

Stack Overflow用户
提问于 2015-10-14 21:00:46
回答 1查看 83关注 0票数 1

我编辑了前面的问题,因为它太长太烦人了,现在我已经弄清楚了我想要的东西,我看到在下面代码中的一些操作中有一个小故障。寻求建议。

我有代码,现在它像我期望的那样工作,但我得到一个额外的0行,不能理解为什么?有什么建议吗?

代码

代码语言:javascript
复制
#!/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

输出

代码语言:javascript
复制
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,不知道为什么??任何建议

EN

回答 1

Stack Overflow用户

发布于 2015-10-14 22:54:41

我相信我这样做是正确的,所以我自己修改了代码,这就是我怎么做的

代码语言:javascript
复制
#!/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操作,因为列很好。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33126020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档