Bash: Converting 4 columns of text interleaved lines (tab-delimited columns to FASTQ file)

336 views Asked by At

I need to convert a 4-column file to 4 lines per entry. The file is tab-delimited.

The file at current is arranged in the following format, with each line representing one record/sequence (with millions of such lines):

@SRR1012345.1   NCAATATCGTGG    #4=DDFFFHDHH    HWI-ST823:136:C24YTACXX
@SRR1012346.1   GATTACAGATCT    #4=DDFFFHDHH    HWI-ST823:136:C22YTAGXX

I need to rearrange this such that the four columns are presented as 4 lines:

@SRR1012345.1
NCAATATCGTGG
#4=DDFFFHDHH
HWI-ST823:136:C24YTACXX
@SRR1012346.1
GATTACAGATCT
#4=DDFFFHDHH
HWI-ST823:136:C22YTAGXX

What would be the best way to go about doing this, preferably with a bash one-liner? Thank you for your assistance!

3

There are 3 answers

0
Ed Morton On
$ awk -v OFS='\n' '{$1=$1}1' file
@SRR1012345.1
NCAATATCGTGG
#4=DDFFFHDHH
HWI-ST823:136:C24YTACXX
@SRR1012346.1
GATTACAGATCT
#4=DDFFFHDHH
HWI-ST823:136:C22YTAGXX
0
hek2mgl On

You can use tr:

< file tr '\t' '\n' > newfile
3
Jason Hu On

very clear to use awk here:

awk '{print $1; print $2; print $3; print $4}' file