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
trim fields using sed stonemonolith Shell Programming and Scripting 3 02-23-2009 04:16 PM
trim lines melanie_pfefer Shell Programming and Scripting 6 03-26-2008 07:25 AM
trim file tungaw2004 UNIX for Dummies Questions & Answers 1 09-15-2007 06:05 AM
trim letters fed.linuxgossip Shell Programming and Scripting 10 05-15-2007 10:11 PM
Trim JWilliams Shell Programming and Scripting 4 04-24-2007 02:52 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 03-17-2009
AlbertGM AlbertGM is offline
Registered User
  
 

Join Date: Mar 2009
Location: Barcelona - Catalonia
Posts: 28
another trim question using tr

Hi all,

I've been looking for how to eliminate blank spaces in a variable or strings. I've seen several ways, using sed, awk and even python. One of them is use 'tr' command, but it does not work as I expected: For example:
Code:
echo "     stuff      " | tr -s " "
leaves one space ahead and another behind. Why?
I also tried
Code:
echo "     stuff      " | tr -d " "
and it works successfully. However, all samples I've seen with "tr", use -s option (which I guess it means replace) rather than -d option.
I'd like to know why.

Thanks a lot.

Albert.
  #2 (permalink)  
Old 03-17-2009
sunpraveen's Avatar
sunpraveen sunpraveen is offline
Registered User
  
 

Join Date: Jan 2009
Location: Pruthvi
Posts: 85
Albert, u can use the below. Works on bash and ksh.

Code:
 
echo "     stuff      " | tr -d [:space:]
HTH,

Regards,

Praveen
  #3 (permalink)  
Old 03-17-2009
AlbertGM AlbertGM is offline
Registered User
  
 

Join Date: Mar 2009
Location: Barcelona - Catalonia
Posts: 28
Thanks sunpraveen, although it is not exactly what I asked for . However, it does help !!!

Albert.
  #4 (permalink)  
Old 03-17-2009
Goldorakk's Avatar
Goldorakk Goldorakk is offline
Registered User
  
 

Join Date: Feb 2009
Location: France
Posts: 43
-d Delete all occurrences of input characters that are specified
-s Replace instances of repeated characters with a single character

Delete vs replace by a single char.

Did you try "-ds" ?
Closed Thread

Bookmarks

Tags
trim

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 02:55 AM.


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