?
Solved

Removing spaces..

Posted on 2003-02-19
7
Medium Priority
?
168 Views
Last Modified: 2013-12-25
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.
0
Comment
Question by:Toraton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 100 total points
ID: 7984078
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
 
LVL 2

Expert Comment

by:shirjeel
ID: 7986375
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
 

Assisted Solution

by:amitabhrai
amitabhrai earned 100 total points
ID: 7988789
with perl you might want to use
$data =~ s/ *$//;
to remove multiple spaces at the end of each line.
0
 

Expert Comment

by:SteveFerson
ID: 8004897
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
 

Expert Comment

by:Ganet
ID: 8016157
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

Featured Post

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question