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
  #1 (permalink)  
Old 12-28-2008
Registered User
 

Join Date: Dec 2008
Posts: 9
Awk Command

Hi, ive got this piece of script:

echo "Enter your full name" (i.e. first and last name)
read name
echo "Hello Mr.(last name only)

How do i split the string so that it says hello and then only displays the surname entered? The user has to be able to enter their name all on one line. i know im meant to use the awk command but im a noob at this. Any help you can give me would be very much appreciated. Thanks, Phil
Sponsored Links
  #2 (permalink)  
Old 12-28-2008
DukeNuke2's Avatar
Soulman
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 2,232
this doesn't mean you need to use awk. the "cut" command maybe enough for your needings. read the manpage of "cut" and tryout some examples...
  #3 (permalink)  
Old 12-28-2008
Registered User
 

Join Date: Dec 2008
Location: .at
Posts: 1,067
try 'read first last', which will split the input on ' ', giving you the first word in $first and the rest of the input in $last
  #4 (permalink)  
Old 12-28-2008
Registered User
 

Join Date: Dec 2008
Posts: 9
Hmmm, ive just asked a friend and he reckons its meant to be something like this:

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

This doesnt actually work, but am i on the right lines? im not trying to split a file, just the string.

Is that wrong then? Thanks v. much for the quick reply.
  #5 (permalink)  
Old 12-28-2008
DukeNuke2's Avatar
Soulman
 

Join Date: Jul 2006
Location: Germany, Berlin
Posts: 2,232
why are you tryin to use "awk" if other commands also work?
  #6 (permalink)  
Old 12-28-2008
Registered User
 

Join Date: Dec 2008
Posts: 9
'read first last'? Sorry im new to this, could you explain a bit more pls?
  #7 (permalink)  
Old 12-28-2008
Registered User
 

Join Date: Dec 2008
Posts: 9
The only reason im using awk is because i was advised that was the best way to do this..... Is there another easier way??
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:47 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