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
how to protect white space in for loop pondlife Shell Programming and Scripting 6 07-01-2008 04:38 AM
stripping white space... Zak Shell Programming and Scripting 7 10-09-2007 04:41 AM
Add white space to the end of a line with sed karlanderson Shell Programming and Scripting 4 08-09-2007 08:26 AM
How to get just the word and clean the white space? paulofp Shell Programming and Scripting 2 06-22-2007 03:28 PM
How to keep white space is being deleted using read keelba Shell Programming and Scripting 1 05-30-2002 11:15 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-25-2008
ski ski is offline
Registered User
 

Join Date: Jul 2008
Posts: 2
Smile Combine fields and eliminate white space

Good Morning,
Newbie here. Could someone help with shell scripting that will enable me to combine 2 fields into one eliminating the white space. The fields are fixed but the data of course varies.
For example:
First Name: "George " 20 positions"
Last Name: "Washington " 30 positions"

I need to create one field with First and Last Name eliminating the space after George into a fixed field length of 50.

Result:
Name: "George Washington "

Appreciate any help.
Thanks.
Reply With Quote
Forum Sponsor
  #2  
Old 07-25-2008
joeyg's Avatar
Moderator
 

Join Date: Dec 2007
Location: Home of world champion Boston Celtics
Posts: 983
Cool take a look at the following

Code:
> 
> fname="George              "
> lname="Washington          "
> full=$(echo $fname $lname)
> echo $full
George Washington
> echo "$full" "*"
George Washington *
> fullt=$(printf "%-50s" "$full")
> echo "$fullt" "*"
George Washington                                  *
>
I used the "*" to help see spacing on the screen.
The printf commands was the key.
Also be careful of use of " " around variables; using means extra space characters are kept while not using and the shell will truncate extra space characters.
Reply With Quote
  #3  
Old 07-25-2008
ski ski is offline
Registered User
 

Join Date: Jul 2008
Posts: 2
Talking Thankyou so much!!

Joey,
Your instructions were very clear and worked perfectly. You've made my day as I've been working on trying to figure this out for awhile.
Have a Great Day!
Toni
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0