Saturday, September 8, 2018

unix - A Bash command to go through a list of files in a directory, find are replicates numbers 1-9, and concatenate them into a new file

I have a directory with a bunch of files
Ex:


ExperimentA_Rep1.bed
ExperimentA_Rep2.bed
ExperimentA_Rep3.bed
ExperimentB_Rep1.bed
ExperimentD_Rep1.bed
ExperimentC_Rep1.bed
ExperimentC_Rep2.bed
.
.
.
ExperimentZ_Rep5.bed

I need to scan through the filenames in a directory and concatenate the files that are from the same experiment, but different replicates, into a new file.


I.e


cat ExperimentA_Rep1.bed ExperimentA_Rep2.bed > ExperimentA_merged.bed

If the Experiment only has 1 replicate, it should not do anything. But I can't hardcode this, it needs to be applicable for any dataset of experiments.


If I ran a python script that would be okay.

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...