Duplicate Block in Tab Delimited File and replace a word

43 views Asked by At

I currently have the following sample text file: http://pastebin.com/BasTiD4x

and I need to duplicate the CDS blocks. Essentially the line that has the word "CDS" and the 4 lines after it are part of the CDS block.

I need to insert this duplicated CDS block right before a line that says CDS, and I need to change the word CDS in the duplicated block to mRNA.

Of course this needs to happen every time there is an instance CDS.

A sample output would be here: http://pastebin.com/mEMAB50t

Essentially for every CDS block, I need an mRNA block that says exactly the same thing.

Would appreciate help with this, never done 4 line insertions and replacements.

Thanks, Adrian

1

There are 1 answers

0
AdrianP. On

Sorry for the very specific question. Here is a working solution provided by someone else:

perl -ne 'if (! /^\s/){$ok=0;if($mem){$mem=~s/CDS/mRNA/;print $mem;$mem="";}}$ok=1 if (/\d+\s+CDS/);if($ok){$mem.=$_};print;' exemple