Search code examples
sedfastq

Replacing a pattern from Fastq file headers using sed cammand


I have a fastq file and i need to edit its header as needed by trinity. My headers are like this :

  1. @SRR1561197.1.1 HWI-ST1379:100:C29NPACXX:7:1101:2115:2122 length=102
  2. @SRR1561197.2.1 HWI-ST1379:100:C29NPACXX:7:1101:2202:2120 length=102
  3. @SRR1561197.3.1 HWI-ST1379:100:C29NPACXX:7:1101:2319:2125 length=102
  4. @SRR1561197.4.1 HWI-ST1379:100:C29NPACXX:7:1101:2510:2121 length=102

In the above headers the Bold text keeps on changing with each header other text remains same. Now i want all header to be replace in one go with a pattern that results in the following headers:

@MexD1SRR1561197.1/1
@MexD1SRR1561197.2/1 
@MexD1SRR1561197.3/1
@MexD1SRR1561197.4/1

i used the following commands but it didnt changed anything:

sed 's/ HWI.*/\/1/g' SRR1561197_1.fastq > change.fastq

sed 's/ HWI.+/\/1/g' SRR1561197_1.fastq > change.fastq

Please help anyone?


Solution

  • I suspect that this is what you want:

    sed 's|^@|@MexD1|;  s| HWI.*|/1|g' SRR1561197_1.fastq > change.fastq
    

    Note that HWT was changed to HWI.