I have 60 text files of different lengths and same column names.

For example:

cat Sample_145_Chimeric.out.junction.new.back_spliced_junction.bed.Circexplorer2.txt | gawk '{print $14}' | sort | uniq -c
  19258 circRNA
    612 ciRNA

cat Sample_146_Chimeric.out.junction.new.back_spliced_junction.bed.Circexplorer2.txt | gawk '{print $14}' | sort | uniq -c
  17791 circRNA
    729 ciRNA

cat Sample_147_Chimeric.out.junction.new.back_spliced_junction.bed.Circexplorer2.txt | gawk '{print $14}' | sort | uniq -c
  22838 circRNA
    686 ciRNA

cat Sample_148_Chimeric.out.junction.new.back_spliced_junction.bed.Circexplorer2.txt | gawk '{print $14}' | sort | uniq -c
  19404 circRNA
    475 ciRNA

I want to produce a 'master' table of all identified circRNAs, with readnumber as column for each sample and flankintronas rownames:

screen shot of the file


If all of the columns in all of the files are in the same order, then just concat them together with >>:

for x in {1..60}; do 
    # These flags for tail just cut of the top line, which is your headers
    tail -n 2 Sample_$x_blah.txt >> Sample_master.txt
    # and the double carat makes the output append^ 

If not, then you can write the translations in awk sort of like you had above, i.e.

$ cat Sample_1.txt 
col1,col2,col3,col4 #etc 
$ cat Sample_2.txt 
$ cat Sample_1.txt > Sample_Master.txt # no translation needed
$ awk '{print $4","$3","$2","$1 }' Sample_2.txt >> Sample_Master.txt 

But with 60 files, that would be more work than- something like writing a python script using python's csv lib...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.