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
Remove extra spaces in a line vikas027 Shell Programming and Scripting 6 10-10-2008 10:07 AM
Remove Trailing spaces after a delimiter kiran_418 UNIX for Dummies Questions & Answers 1 04-29-2008 02:19 PM
How to remove trailing spaces mahek_bedi UNIX for Dummies Questions & Answers 2 08-10-2007 07:21 AM
Trim trailing spaces from each line in a file tipsy Shell Programming and Scripting 5 09-13-2006 05:48 AM
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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-17-2008
vikas_kesarwani vikas_kesarwani is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 17
Question remove trailing spaces from a line

I want to remove the trailing spaces from any line of file.
line ending does not follow any pattern.
plz help
  #2 (permalink)  
Old 11-17-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,257
Code:
root@isau02:/data/tmp/testfeld> od -c infile
0000000   a   b   c       m   o   n          \t          \t          \n
0000020   f   i   e   l   d   1       f   i   e   l   d   5[b]          \t
0000040  \t      \t  \t      \t              \t      \t      \t  \n
0000057
root@isau02:/data/tmp/testfeld> sed 's/[[:space:]]*$//' infile| od -c
0000000   a   b   c       m   o   n  \n   f   i   e   l   d   1       f
0000020   i   e   l   d   5  \n
0000026
  #3 (permalink)  
Old 11-17-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
If your sed version doesn't support the POSIX Character Classes you can use a space and a \t within the square brackets:

Code:
sed 's/[ \t]*$//'
Older versions of sed even doesn't recognize the \t as a tab. In that case you can type <Ctrl-V> <TAB> successively instead of \t:

Code:
sed 's/[     ]*$//'
Regards

Last edited by Franklin52; 11-17-2008 at 09:26 AM..
  #4 (permalink)  
Old 11-17-2008
vikas_kesarwani vikas_kesarwani is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 17
thnx a lot buddy
Sponsored Links
Closed Thread

Bookmarks

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 08:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
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