lady has asked for the wisdom of the Perl Monks concerning the following question:

I have created a program that selects the DNA from a genbank file. However, I need to turn this DNA into fasta format which means creating a line that looks like this:
> Gene name GCGATGCTAGTCGTAGTCATGCAGG CGGATTGT
I need to find out how to add the '>' symbol to the start of a file. I have been thinking so hard my brain hurts. Can it be done with a regular expression?? I know you can substitute characters, but can you add them?? Thanks.

Replies are listed 'Best First'.
Re: Adding characters to the beginning of a file
by belg4mit (Prior) on Apr 17, 2002 at 13:34 UTC
Re: Adding characters to the beginning of a file
by tachyon (Chancellor) on Apr 17, 2002 at 15:25 UTC

    Perl of course has a one liner for this using the inplace edit feature. This does the trick (and writes a backup file of the original with a .bak appended just in case :-)

    perl -pi.bak -e '$begin++ || s/^/>/' dna.txt

    This does what you have to do. Read the file in and write out a new modified file. You need to use " instead of ' on Win32.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print