How to Remove Space in text file

R

Rita

Hi
I have data
$seq = ABCHDJJKOLEUOEJLDXJFXLJLCXJFLDFJDFUPD
ASJKDJIUEOFJLDFJOFUEOF
DNBKASCDFHIEFYHKHCAKDFHDGTAAAACAC
TATCAACAAACATTTTCAT
This is one sequence and I Want to remove Enter Space from in it
I am using Regular Expraision
($seq =~ s/\n\s /sg);
But its reading just first line.
I donot know why? Can somebody help me?
Thanks
 
B

Brian Wakem

Rita said:
Hi
I have data
$seq = ABCHDJJKOLEUOEJLDXJFXLJLCXJFLDFJDFUPD
ASJKDJIUEOFJLDFJOFUEOF
DNBKASCDFHIEFYHKHCAKDFHDGTAAAACAC
TATCAACAAACATTTTCAT


Bareword "ABCHDJ......." not allowed while "strict subs" in use at -e line
1.

Not a good start.

This is one sequence and I Want to remove Enter Space from in it
I am using Regular Expraision
($seq =~ s/\n\s /sg);


A) The pattern does not occur anywhere in the string.
B) The second half of your substituion is missing.


But its reading just first line.


Maybe, but what you've posted is barely even perl, so how can we determine
why?

Please post *real* code.
 
B

Brian Wakem

Rita said:
Sorry I write wrong by mistake
i am using
($seq =~ s/\s//sg);
Is It I am doing something wrong?


Works fine for me.


#!/usr/bin/perl

use strict;

my $seq = <<SEQ;
ABCHDJJKOLEUOEJLDXJFXLJLCXJFLDFJDFUPD
ASJKDJIUEOFJLDFJOFUEOF
DNBKASCDFHIEFYHKHCAKDFHDGTAAAACAC
TATCAACAAACATTTTCAT
SEQ

$seq =~ s/\s//sg;

print "$seq\n";

____________________________


$ perl scripts/tmp/tmp64.pl
ABCHDJJKOLEUOEJLDXJFXLJLCXJFLDFJDFUPDASJKDJIUEOFJLDFJOFUEOFDNBKASCDFHIEFYHKHCAKDFHDGTAAAACACTATCAACAAACATTTTCAT
 
B

Big and Blue

Rita said:
I have data
$seq = ABCHDJJKOLEUOEJLDXJFXLJLCXJFLDFJDFUPD
ASJKDJIUEOFJLDFJOFUEOF
DNBKASCDFHIEFYHKHCAKDFHDGTAAAACAC
TATCAACAAACATTTTCAT

I presume that you mean you have a string that contains several
newlines in it (it's only a "sequence" in biological terms).
This is one sequence and I Want to remove Enter Space from in it

I presume by Enter you mean newline.

I am using Regular Expraision
($seq =~ s/\n\s /sg);
But its reading just first line.

(I think that final / should be //). You haven't actually given us any
code to work with, so we'll have to guess.

The code isn't "reading" any line, but it may only be changing the
first line (as you see it). That regex appears to be forcing \n to be
followed by \s then by a space before any substitution is done. If you've
only got a \n then nothing will happen.

Assuming you want to get rid of all newlines and spaces why not ask for
that?

$seq =~ s/\s+//g;

Alternatively, don't get them in the string in the first place. If you
are reading this from a file then chomp() as you go.
 
R

Rita

Assuming you want to get rid of all newlines and spaces why not ask for
that?

$seq =~ s/\s+//g;

Alternatively, don't get them in the string in the first place. If you
are reading this from a file then chomp() as you go.
Thanks
I already did chomp() but it was not working.
anyways I use join function here and it's working now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top