The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]

 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Newer Topic  |  Older Topic 
 Using both "grep" & "awk" in a pipeline
Author: David Wolfskill 
Date:   11-10-01 17:58

Happened across the example for extracting the IP address,
which involves a pipeline similar to the following (translated
to use the NIC I happen to have on the machine I'm using at the
moment):

ifconfig an0 | grep "inet " | awk '{print $2}'

Comment is that it's fairly rare to actually need the "grep"
invocation if you're invoking "awk" anyhow; try:

ifconfig an0 | awk '/inet / {print $2}'

(Hmmm... looking at this, I note that it you have multiple IP
addresses assigned to the NIC in question -- of course, for this
application, no one would do that, I suppose.... Anyhow, things
could get Fairly Weird for someone who might try such a thing.)

Reply To This Message
 Forum List  |  Threaded View   Newer Topic  |  Older Topic 


 Forum List  |  Need a Login? Register Here 
 User Login
 User Name:
 Password:
 Remember my login:
   
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.
How to get the most out of the forum

phorum.org