![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
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 * > 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
|
|||
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |