title: How to paste the columns from a file to another temp file?
body: <p>I have edited the previous question since it was way too long and annoying, now that I have figured out the things I wanted I see there is one minor glitch in some operation in the below code. Seek advice.</p>
  
  <p>I have code and now it works as I expect but I get an additional row with 0, am not being able to understand why? any advice?</p>
  
  <p>code</p>
  
  <pre><code>#!/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 &gt; tmp
  printf "chr\tstart\tend" &gt; tsamples
  for file in `ls *.bed`; do
      printf "\t" &gt;&gt; tsamples
      printf `basename $file .bed` &gt;&gt; tsamples
      #echo $file | cut -d_ -f 1,2,3 &gt;&gt; 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 - &gt; tmp2
      mv tmp2 tmp
  done
  echo "" &gt;&gt; tsamples
  cat tsamples tmp &gt; histone_marks.map
  rm tsamples tmp
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Everything is fine except the last row shows a 0, do not know why?? any advice</p>