newbie awk question 
Author Message
 newbie awk question

Hi,
i wanted to know if there was an awk way of doing the following:

here's a code snipet:

FILE=/etc/profile
FILENAME=`echo $FILE | awk -F/ '{print $3}'`

Ok, FILENAME will equal "profile".  Here's my question.  Is there an awk
print option or variable, etc.. that will allow me to get the value of only
THE LAST column (profile) without using $3?

for example:
FILE=/etc/inet/hosts    <-- instead of {print $4} to get "hosts" is there a
way like:  $<VALUE_OF_LAST_FIELD>  will equal hosts. hope the question makes
sense.  thanks,

jim



Mon, 24 May 2004 22:57:58 GMT  
 newbie awk question

Quote:

>Hi,
>i wanted to know if there was an awk way of doing the following:

>here's a code snipet:

>FILE=/etc/profile
>FILENAME=`echo $FILE | awk -F/ '{print $3}'`

>Ok, FILENAME will equal "profile".  Here's my question.  Is there an awk
>print option or variable, etc.. that will allow me to get the value of only
>THE LAST column (profile) without using $3?

>for example:
>FILE=/etc/inet/hosts    <-- instead of {print $4} to get "hosts" is there a
>way like:  $<VALUE_OF_LAST_FIELD>  will equal hosts. hope the question makes
>sense.  thanks,

Use print $NF

NF is the number of fields on the present line.

Chuck Demas

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Mon, 24 May 2004 23:29:19 GMT  
 newbie awk question

Quote:
> Hi,
> i wanted to know if there was an awk way of doing the following:

> here's a code snipet:

> FILE=/etc/profile
> FILENAME=`echo $FILE | awk -F/ '{print $3}'`

> Ok, FILENAME will equal "profile".  Here's my question.  Is there an
awk
> print option or variable, etc.. that will allow me to get the value of
only
> THE LAST column (profile) without using $3?

> for example:
> FILE=/etc/inet/hosts    <-- instead of {print $4} to get "hosts" is
there a
> way like:  $<VALUE_OF_LAST_FIELD>  will equal hosts. hope the question
makes
> sense.  thanks,

> jim

If you have basename on your system then that's probably easier than
using awk.

man basename

HTH
--
Peter S Tillier
"Who needs perl when you can write dc in sed?"
peter dot tillier at btinternet dot com
To reply direct to me please use the above address
not the "Reply To" which activates a spam trap.



Mon, 24 May 2004 23:42:16 GMT  
 newbie awk question
[[ This message was both posted and mailed: see
   the "To," "Cc," and "Newsgroups" headers for details. ]]


X  Hi,
X  i wanted to know if there was an awk way of doing the following:
X  
X  here's a code snipet:
X  
X  FILE=/etc/profile
X  FILENAME=`echo $FILE | awk -F/ '{print $3}'`
X  
X  Ok, FILENAME will equal "profile".  Here's my question.  Is there an awk
X  print option or variable, etc.. that will allow me to get the value of only
X  THE LAST column (profile) without using $3?
X  
X  for example:
X  FILE=/etc/inet/hosts    <-- instead of {print $4} to get "hosts" is there a
X  way like:  $<VALUE_OF_LAST_FIELD>  will equal hosts. hope the question makes
X  sense.  thanks,

If you are using ksh (or a shell that says it supports Korn Shell
syntax), then try the following:

    FILENAME=${FILE##*/}

                                        Bob Harris



Tue, 25 May 2004 04:02:57 GMT  
 newbie awk question
Thank you all for such a quick response.  i'll be playing with all these
suggestions
to see which does best for the script's context.

jim



Tue, 25 May 2004 22:48:43 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. A Newbie AWK question

2. Newbie AWK Question

3. AWK newbie is looking for a AWK help with his 1st program

4. Newbie awk (sed??) question, regular expressions

5. Newbie question -- to make an awk program act on a collection of files

6. AWK for DOS - NewBie Question

7. awk Newbie question

8. Newbie question: how to learn (N)AWK

9. Newbie question on using System() and Awk

10. AWK Newbie Question

11. newbie question on Tcl with awk

12. Newbie Question (Was: Newbie Question...)

 

 
Powered by phpBB® Forum Software