The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
To Trim spaces at the end of line sbasetty Shell Programming and Scripting 1 01-31-2007 10:01 PM
Strip leading and trailing spaces only in a shell variable with embedded spaces jerardfjay Shell Programming and Scripting 6 03-07-2005 02:24 PM
Adding Trailing Spaces to a file 222001459 UNIX for Dummies Questions & Answers 1 11-04-2004 03:23 PM
Leading and Trailing Spaces sleepster Shell Programming and Scripting 7 10-29-2003 11:48 PM
removing trailing spaces of a particular column in a file rooh UNIX for Dummies Questions & Answers 2 01-12-2002 11:34 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-31-2006
tipsy tipsy is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 35
Thumbs up Trim trailing spaces from each line in a file

Hello folks,
Is there a simple way to trim trailing spaces from each line a file. Please let me know.

Regards,
Tipsy.
  #2 (permalink)  
Old 08-31-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
sed 's/[ ]*$//' old > new
  #3 (permalink)  
Old 08-31-2006
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
One more thing.

add a \t to the "[ ]" set to include tabs
  #4 (permalink)  
Old 08-31-2006
tipsy tipsy is offline
Registered User
  
 

Join Date: Jun 2006
Posts: 35
Thanks tmarikle.

Regards,
Tipsy.
  #5 (permalink)  
Old 09-13-2006
kalyanraj kalyanraj is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 6
hi,

The following can be accomplised using Perl script also

[code]
open(i,"<$filein") || die "Can't open $!\n ";
while (!eof(i)) {
$line = <i>;
push @temp, $line;
}
close(i);

foreach $line(@temp) {
$line =~ s/\s+$//o;
}
[\code]

Thanks,
Raj
  #6 (permalink)  
Old 09-13-2006
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
Quote:
Originally Posted by tipsy
Hello folks,
Is there a simple way to trim trailing spaces from each line a file. Please let me know.

Regards,
Tipsy.
In Python, if you have it:
Code:
>>> for lines in open("yourfile.txt"):
>>>      print  lines.strip()
Closed Thread

Bookmarks

Tags
awk, awk trim, trim, trim awk

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:59 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0