How do I put each character in a text file on individual lines using a perl script?

I have a text file with a large number of letters (representing a DNA sequence) with 100 letters on each line. How can I manipulate the file so that each line in the perl script contains one character?

2 Responses to “How do I put each character in a text file on individual lines using a perl script?”

  • Yahgoogle:

    Just 2 lines code:
    ######## Convert.pl ###########
    local $/=undef;
    for (split(//,<>)) { print $_, "\n" }
    #############################
    usage: perl convert.pl < input.txt > output.txt

    *****************************************
    You can also use tool Replace Pioneer:
    1. ctrl-o open source file.
    2. ctrl-h open replace window:
    * search for pattern .(single dot)
    * replace with pattern $match\n
    3. click ‘Replace’, done!
    *****************************************
    Replace Pioneer free trial download:

  • Tizio 008:

    if you mean you want loop over each letter of every line, something like

    while($line = <file>)
    {
    @letters = split //, $line;
    foreach $l ( @letters )
    {
    print $l;
    }
    }

    or something similar.

Leave a Reply