By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,834 Members | 2,234 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,834 IT Pros & Developers. It's quick & easy.

I want to Remove Space from a text file conatining a sequence in FASTA format.

P: 4
TEXT file conatins: INPUT FILE
CGGCAGGACCGAGCGCGGCAGGCGGCTGGCCCAGCGCAGCCAGCGCGGCC CGAAGGACGGGAGCAGGCGG
CCGAGCACCGAGCGCTGGGCACCGGGCACCGAGCGGCGGCGGCACGCGAG GCCCGGCCCCGAGCAGCGCC
CCCGCCCGCCGCGGCCTCCAGCCCGGCCCCGCCCAGCGCCGGCCCGCGGG GATGCGGAGCGGCGGGCGCC
GGAGGCCGCGGCCCGGCTAGGCCCGCGCTCGCGCCCGGACGCGGCGGCCC GAGGCTGTGGCCAGGCCAGC
TGGGCTCGGGGAGCGCCAGCCTGAGAGGAGCGCGTGAGCGTCGCGGGAGC CTCGGGCACCATGAGCGACG
TGGCTATTGTGAAGGAGGGTTGGCTGCACAAACGAGGGGAGTACATCAAG ACCTGGCGGCCACGCTACTT
CCTCCTCAAGAATGATGGCACCTTCATTGGCTACAAGGAGCGGCCGCAGG ATGTGGACCAACGTGAGGCT


I want output in a single line with no new line character or space like this:
CGGCAGGACCGAGCGCGGCAGGCGGCTGGCCCAGCGCAGCCAGCG..... .........................NO SPACE i want
Feb 7 '10 #1
Share this Question
Share on Google+
6 Replies


Expert Mod 100+
P: 589
One solution. use a regex.
Expand|Select|Wrap|Line Numbers
  1. $fasta =~ s/[\n\s]//g;
Feb 7 '10 #2

P: 4
$file = 'file1.txt';
open(FILEHANDLE, "<$file");
$file=~ s/[\n\s]//g;
print <FILEHANDLE>;
close(FILEHANDLE);


I m very new to Programming. I am doing this...But unable to remove spaces.
Feb 7 '10 #3

Expert Mod 100+
P: 589
If that's all you need to do, then a simple 1 liner from the command line will suffice.

C:\test>perl -pi.bak -e "s/[\n\s]//g;" file1.txt
Feb 7 '10 #4

P: 4
THANKS....U r NICE.....Thnx for Replying too fast....
Feb 7 '10 #5

Expert Mod 100+
P: 589
You're Welcome :-)

Since I replied "too fast", should I slow down next time? :o)
Feb 7 '10 #6

P: 4
Nooooooo>>>>......yaar You are Such a Darling....i appreciate ur concern.
Feb 7 '10 #7

Post your reply

Sign in to post your reply or Sign up for a free account.