Removing spaces..

Every line of data ends with a carriage return and what looks like a space. I can remove the carriage returns, but how do I remove a space only at the end of the data? if I remove any spaces inside the data, the purpose is lost.Thanks.
ToratonAsked:
Who is Participating?
 
TintinConnect With a Mentor Commented:
Assuming the variable $data has the data and assuming you are using Perl (since you didn't specify what language you are using)

$data =~ s/ $//;
0
 
shirjeelCommented:
Dear Toraton,

I Think you are facing a problem in moving files from windows to unix or linux system. if it is so then the problem is of carriage return. you can use different ways to transfer the files so that you can avoid this problem. like if you are moving files through any ftp software then use ASCII mode it will autmotically remove carriage returns. secondly there is a command too in linux to remove any text from the whole file but i forgot its syntax now.

Shirjeel
0
 
amitabhraiConnect With a Mentor Commented:
with perl you might want to use
$data =~ s/ *$//;
to remove multiple spaces at the end of each line.
0
 
SteveFersonCommented:
I think you guys should make clear that there is a space in your regex (ie before the $ in tintins and before the * in amitabhrai's)
0
 
GanetCommented:
if it is because you are moving the files from windows then windows puts carriage return and line feed together
so try this

$data =~ s/\f//g; # removes line feed characters
$data =~ s/\r//g; # removes carriage return characters
$data =~ s/\n//g; # removes newline characters

assuming you are using $data

this will remove all linefeed, charage return, or new line characters.
0
All Courses

From novice to tech pro — start learning today.