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 > 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
how to protect white space in for loop pondlife Shell Programming and Scripting 6 07-01-2008 07:38 AM
stripping white space... Zak Shell Programming and Scripting 7 10-09-2007 07:41 AM
How to get just the word and clean the white space? paulofp Shell Programming and Scripting 2 06-22-2007 06:28 PM
How to keep white space is being deleted using read keelba Shell Programming and Scripting 1 05-30-2002 02:15 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 07-25-2008
ski ski is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 13
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.
  #2 (permalink)  
Old 07-25-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
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.
  #3 (permalink)  
Old 07-25-2008
ski ski is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 13
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
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 09:55 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