Convert fastq to fasta format with awk

If you need to convert illumina reads in fastq format to fasta format, try using awk. If the reads are compressed, you can extract with zcat, then pipe the output to an awk one-liner:

zcat myReads.fastq.gz | awk 'BEGIN{P=1}{if(P==1||P==2){gsub(/^[@]/,">");print}; if(P==4)P=0; P++}' > myReads.fasta

Otherwise if they aren’t compressed, you can just use awk:

awk 'BEGIN{P=1}{if(P==1||P==2){gsub(/^[@]/,">");print}; if(P==4)P=0; P++}' myreads.fastq > myReads.fasta

Leave a comment