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
problem with output of find command being input to basename command... new_learner UNIX for Dummies Questions & Answers 2 12-14-2008 01: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 12: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

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #15 (permalink)  
Old 12-30-2008
Registered User
 

Join Date: Dec 2008
Posts: 9
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 04:39 PM..
Sponsored Links
  #16 (permalink)  
Old 12-30-2008
pmm pmm is offline
Registered User
 

Join Date: Dec 2008
Posts: 44
To print last name, try:

echo "Please enter your full name:"
read name
echo $name | awk '{print"Hello Mr. " $NF}'
  #17 (permalink)  
Old 01-02-2009
Registered User
 

Join Date: Dec 2008
Posts: 9
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
  #18 (permalink)  
Old 01-02-2009
Registered User
 

Join Date: Apr 2006
Location: Iraq
Posts: 36
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 02:44 PM..
  #19 (permalink)  
Old 01-02-2009
Registered User
 

Join Date: Dec 2008
Posts: 9
Thanks very much TheEngineer that worked perfectly.

And i thank all you that have helped me

Have a good New Year!
  #20 (permalink)  
Old 01-05-2009
Registered User
 

Join Date: Oct 2007
Posts: 87
Try this:

echo "Please enter your full name: "
read name
echo $name | awk '{print $2}'

SINCE I CANNOT RECALL THE ABOVE MSG, PLS IGNORE IT.

Last edited by bobbygsk; 01-05-2009 at 11:32 AM.. Reason: Misunderstood the question
  #21 (permalink)  
Old 01-06-2009
Registered User
 

Join Date: Oct 2008
Posts: 5
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
Google The UNIX and Linux Forums
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 04:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66