use grep or other command to get exactly pattern

Norman Gaywood ngaywood at une.edu.au
Fri Jan 18 20:37:10 UTC 2008


ann kok wrote:
> how can use grep or use other command to get exactly
> pattern eg: 10.0.0.7 only?
>
> eg: grep 10.0.0.7 file. I want to get 10.0.0.7 only
> not  
> 10.0.0.71
> 10.0.0.72
> 10.0.0.7

grep '^10\.0\.0\.7$' file   

The ^ means the start of the line, \. means match a "." character. If
you just used . it means to match any character. $ means the
end of the line.
-- 
Norman Gaywood, Systems Administrator
University of New England, Armidale, NSW 2351, Australia

ngaywood at une.edu.au            Phone: +61 (0)2 6773 3337
http://mcs.une.edu.au/~norm    Fax:   +61 (0)2 6773 3312

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html




More information about the fedora-list mailing list