move fasta and fastq files with the same name folder
1
0
Entering edit mode
9 months ago
cabraham03 ▴ 30

I have multiples files

genome_1.fasta 

genome_1_R1.fastq 

genome_1_R2.fasta 

genome_2.fasta 

genome_2_R1.fastq 

genome_2_R2.fasta

genome_2.fasta 

genome_2_R1.fastq 

genome_2_R2.fasta 

I want to move the files with the same base name to a folder that correspond to each genome name, I mean all genome_1* (fasta and fastq) files will be moved to genome_1/ folder

if I make it for fasta first, and then for fastq, I have no problems

for f in *.fasta; do dir="${f%.fasta}"; mkdir $dir; mv "$f" "$dir"; done

it will create the folder and move all fasta to it now all fastq

for f in *.fastq; do dir="${f%_R*.fastq}";  mv "$f" "$dir"; done

how can I use a single loop to move .fasta, _R1.fastq and _R2.fastq ???

it possible to add multiples patterns for dir variable ? something like:

dir="${f%[.fasta\|_R1.fastq\|_R2.fastq]}"

Thanks

for loop • 456 views
ADD COMMENT
2
Entering edit mode
9 months ago

You can add multiple extension in your for loop.

for f in *.fasta *.fastq; do
    base_name=$(basename "$f" | cut -d. -f1)

    genome_name=$(echo "$base_name" | cut -d_ -f1)

    mkdir -p "$genome_name"

    mv "$f" "$genome_name/"
done
ADD COMMENT
0
Entering edit mode

thanks !!!!

ADD REPLY

Login before adding your answer.

Traffic: 2752 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6