This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Reduce FASTA file name

I have more than 60000 fasta file and which having long name like

BA000031.2_ID=gene0_Name=VP0001_gbkey=Gene_gene=VP0001_gene_biotype=protein_coding.fasta
BA000031.2_ID=gene8_Name=VP0009_gbkey=Gene_gene=VP0009_gene_biotype=protein_coding.fasta

and I want to change like this

VP0001.fasta
VP0009.fasta

like this for all 60000 files how it possible

perl awk fasta genome

2 answers

Use the rename command. Check man rename for available options (rename comes with perl and newer perls have more options).

I'm sure there's an elegant awk solution out there but here's my somewhat shitty loop for it. It assumes all files keep the same structure as the ones you've posted.

for f in *_coding.fasta; do new="$(echo $f | tr '=' '_' | cut -d '_' -f 5)"; mv $f $new.fasta; done

Log in to answer this question.