0

I have hundreds files need to loop through for an analysis using a bash script. One step I need to do is to split a long string and cat it as an output name. For example, suppose I have one string such like:

5018.a.Radiation_Induced_Lymphoma.Tumor__p53+_-.SL200300_SL200300.exome_1tier.mm10.kapa_re_cap_v6_3utr.final.bam

What I wanted is to rename it as two output file names such as:

5018.a.Radiation_Induced_Lymphoma.Tumor__p53+_-.SL200300_SL200300.exome_1tier.mm10.kapa_re_cap_v6_3utr.final_R1.fastq
5018.a.Radiation_Induced_Lymphoma.Tumor__p53+_-.SL200300_SL200300.exome_1tier.mm10.kapa_re_cap_v6_3utr.final_R2.fastq

The only changes are removing .bam from the original and cat _R1.fastq and _R2_fastq. Does somebody know how to realize it using bash commands?

David Z
  • 5,931
  • 8
  • 44
  • 87

1 Answers1

1
somefile=blahblahblah.final.bam
foo "$somefile" "${somefile%.*}_R1.fastq" "${somefile%.*}_R2.fastq"
Ignacio Vazquez-Abrams
  • 740,318
  • 145
  • 1,296
  • 1,325