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
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

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
  #15 (permalink)  
Old 12-30-2008
kazazza kazazza is offline
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 05:39 PM..
  #16 (permalink)  
Old 12-30-2008
pmm pmm is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 50
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
kazazza kazazza is offline
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
TheEngineer TheEngineer is offline
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 03:44 PM..
  #19 (permalink)  
Old 01-02-2009
kazazza kazazza is offline
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
bobbygsk bobbygsk is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 90
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 12:32 PM.. Reason: Misunderstood the question
  #21 (permalink)  
Old 01-06-2009
silvermax silvermax is offline
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
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 10:51 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