Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-12-2009
Registered User
 

Join Date: Dec 2008
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
grep/egrep end of pattern

Hi

I use arp to get the mac-addresses of my hosts.


Code:
 # arp -a | grep 192.168.0.
e1000g0   192.168.0.1            255.255.255.255 o        00:00:00:00:00:01
e1000g0   192.168.0.11          255.255.255.255 o        00:00:00:00:00:02
e1000g0   192.168.0.2            255.255.255.255          00:00:00:00:00:03
e1000g0   192.168.0.22          255.255.255.255 o        00:00:00:00:00:04
e1000g0   192.168.0.3            255.255.255.255          00:00:00:00:00:05
e1000g0   192.168.0.33            255.255.255.255         00:00:00:00:00:06

How can I grep/egrep for just one host? I'd like to have the following:


Code:
 # arp -a | grep "192.168.0.1"
e1000g0   192.168.0.1            255.255.255.255 o        00:00:00:00:00:01

and not


Code:
  # arp -a | grep "192.168.0.1"
 e1000g0   192.168.0.1            255.255.255.255 o        00:00:00:00:00:01
 e1000g0   192.168.0.11          255.255.255.255 o        00:00:00:00:00:02

Sponsored Links
  #2  
Old 05-12-2009
Moderator
 

Join Date: Feb 2007
Location: The Netherlands
Posts: 5,591
Thanks: 2
Thanked 68 Times in 65 Posts
Try the -w option of grep.

Regards
  #3  
Old 05-12-2009
Registered User
 

Join Date: Dec 2008
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks. Exactly what I need.
Sorry for my stupid question
  #4  
Old 05-12-2009
Registered User
 

Join Date: Aug 2008
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
you can also try out as
arp -a | grep "192.168.0.1 "
  #5  
Old 05-12-2009
Moderator
 

Join Date: Feb 2007
Location: The Netherlands
Posts: 5,591
Thanks: 2
Thanked 68 Times in 65 Posts
Quote:
Originally Posted by pradeepreddy View Post
you can also try out as
arp -a | grep "192.168.0.1 "
Why should you use a workaround if there's an option for?

Regards
  #6  
Old 05-12-2009
Registered User
 

Join Date: Dec 2008
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Why should you use a workaround if there's an option for?
My words

But I have an other question:

How can I grep/egrep for exactly two (192.168.1 AND 192.168.2 for example) hosts?


Code:
arp -a | egrep '192.168.0.(1|2)'

This egrep delivers four hosts.

Last edited by domi55; 05-12-2009 at 08:27 AM..
  #7  
Old 05-12-2009
Registered User
 

Join Date: Aug 2008
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
arp -a | awk '{print $2}' | grep "192.168.0.[1-2]$"

check this out
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to grep or egrep pattern of apache access_log file lamoul Solaris 2 05-06-2009 09:21 PM
Simple egrep pattern blondie53403 Shell Programming and Scripting 7 04-14-2009 11:55 AM
HOW to egrep fo a pattern eliewadi Shell Programming and Scripting 1 05-15-2008 10:42 PM
egrep a certain pattern trust123 UNIX for Dummies Questions & Answers 5 06-29-2007 08:23 AM
grep/awk/egrep? whugo UNIX for Dummies Questions & Answers 3 01-19-2006 11:51 PM



All times are GMT -4. The time now is 07:58 AM.