Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: change \n to \t

by Marshall (Canon)
on Aug 24, 2019 at 23:03 UTC ( #11104964=note: print w/replies, xml ) Need Help??


in reply to change \n to \t

Works with huge 1.fa file.

#!/usr/bin/perl use strict; use warnings; while (my $line =<DATA>) { $line =~ s/^\s*|\s*$//g; if ($line =~ /^\d/) { print "$line\t"; } else { print "$line\n"; } } =Prints 1 AGTCGTAGCAT 2 TGAGCTACG 3 GGCATAGN 4 CGCACNCAGCTACACC 5 NGATAGCTACA =cut __DATA__ 1 AGTCGTAGCAT 2 TGAGCTACG 3 GGCATAGN 4 CGCACNCAGCTACACC 5 NGATAGCTACA
To prevent blank lines in output caused by blank lines in 1.fa, add next unless $line =~ /\S/; or similar after removing leading and trailing spaces.

Update: looking back this, if the ">" actually appears in the 1.fa file, then just delete it if seen while processing the line and use the above logic.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11104964]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2021-01-22 00:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?