Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: change \n to \t

by Marshall (Canon)
on Aug 24, 2019 at 23:03 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11104964]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-25 08:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found