![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| problem with output of find command being input to basename command... | new_learner | UNIX for Dummies Questions & Answers | 2 | 12-14-2008 02:56 AM |
| awk/sed Command : Parse parameter file / send the lines to the ksh export command | rajan_san | Shell Programming and Scripting | 4 | 11-06-2008 01:29 PM |
| assign a command line argument and a unix command to awk variables | sweta_doshi | Shell Programming and Scripting | 0 | 08-08-2008 06:54 AM |
| Help Required: Command to find IP address and command executed of a user | loggedout | Security | 2 | 08-06-2008 08:12 PM |
| inconsistent ls command display at the command prompt & running as a cron job | rajranibl | SuSE | 5 | 07-30-2007 08:26 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
When i use the code:
echo "Please enter your full name:" read name echo $name | awk '{print"Hello Mr." $2}' And enter a first middle and surname e.g. john bloggs smith then it outputs 'Hello Mr. bloggs' instead of 'Hello Mr. smith'. And if i use the code: echo $name | awk '{print"Hello Mr." $0}' And enter a first middle and surname e.g. john bloggs smith then it outputs 'Hello Mr. john bloggs smiths' instead of 'Hello Mr. smith'. AHHH lol. Thanks very much for all your help Last edited by kazazza; 12-30-2008 at 05:39 PM.. |
|
||||
|
Thanks PMM that worked great!
I'm trying to improve this now, so that it doesn't greet everyone as "Mr." So I've made a variable called "title" (referring to Mr. Mrs. etc) my ONLY problem now is that i don't know how to order the command. This is what i have atm: echo $name | awk '{print"Hello $title " $NF}' I've tried putting the $title bit in different places, but no luck.... Thanks for all your help everyone. Phil |
|
||||
|
Hello kazazza
AWK need a mapping in order to read normal shell variables, you'd rather need to re-form your command as below to get the desired result: title="Mr" echo "Please Enter your name: " read name echo $name | awk -v awk_title=$title '{print "hello " awk_title ". " $NF}' or you can assign the title variable from within AWK echo "Please Enter your name: " read name echo $name | awk BEGIN '{title="Mr"} {print "Hello " title ". " $NF}' Last edited by TheEngineer; 01-06-2009 at 03:44 PM.. |
|
||||
|
echo "Please enter your full name:"
read first last echo $last as long as the user input has a space between John & Doe then $first=John $last=Doe |
| Sponsored Links | ||
|
|