The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Add white space to the end of a line with sed karlanderson Shell Programming and Scripting 7 03-09-2009 06:20 AM
SED with White Space sandeep_1105 UNIX for Dummies Questions & Answers 1 03-02-2009 04:48 PM
stripping white space... Zak Shell Programming and Scripting 7 10-09-2007 08:41 AM
trimming white spaces briskbaby Shell Programming and Scripting 9 09-23-2006 07:10 PM
Sh scripting problem, matching specific white space Dickalicious Shell Programming and Scripting 7 05-24-2006 02:30 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-04-2009
sandeep_1105 sandeep_1105 is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 29
Problem with Trimming of white space

Dear Members,

Following is the code which i am using:

integer i=7
while ((i <= 10 ));
do
param[i]=`echo $TEST_OUT | cut -d"^" -f$i`

a=`echo ${param[7]}`
echo `echo $a | sed 's/+/ /g'`

(( i = i + 1));
done


From the above code TEST_OUT is a variable which has the following value:

TEST_OUT='12345++++++TEST COMPANY+++++++++02182009+++++++01232009+++++++FREIGHT PAYMENT+++5.64'

as you can see all the values in TEST_OUT are separated by '+' sign.

MY aim is to replace the '+' sign with a white space, so i am using the following command:

echo `echo $a | sed 's/+/ /g'`

If i do this it is replacing '+' with only one white space. The result looks like

'12345 TEST COMPANY 02182009 01232009 FREIGHT PAYMENT 5.64'

which i don't want. Suppose we have 7 '+' sign then i would like to see 7 white spaces which is not happening. Its only putting one space.

How can i avoid this.

I am using Korn Shell.

Thanks
Sandeep
  #2 (permalink)  
Old 03-04-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
$ TEST_OUT='12345++++++TEST COMPANY+++++++++02182009+++++++01232009+++++++FREIGHT PAYMENT+++5.64'
$ echo "$TEST_OUT" | sed 's/+/ /g'
12345      TEST COMPANY         02182009       01232009       FREIGHT PAYMENT   5.64
$ echo `echo "$TEST_OUT" | sed 's/+/ /g'`
12345 TEST COMPANY 02182009 01232009 FREIGHT PAYMENT 5.64

Why do you need a leading echo?
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 03:12 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