grep exact pattern from a file in bash -


i have following ip addresses in file

3.3.3.1 3.3.3.11 3.3.3.111 

i using file input file program. in program grep each ip address. when grep contents getting wrong outputs.

like

cat testfile | grep -o 3.3.3.1 

but getting output like

3.3.3.1 3.3.3.1 3.3.3.1 

i want exact output. how can grep?

use following command:

grep -owf "3.3.3.1" tesfile 

-o returns match , not whole line.-w greps whole words, meaning match must enclosed in non word chars <space>, <tab>, ,, ; start or end of line etc. prevents grep matching 3.3.3.1 out of 3.3.3.111.

-f greps fixed strings instead of patterns. prevents . in ip address interpreted any char, meaning grep not match 3a3b3c1 (or this).


Comments

Popular posts from this blog

java - HTTP Status 500 - An exception occurred processing JSP page /second.jsp at line 15 -

php - Using str_replace to translate a MySQL Table in html -

asp.net mvc - Cannot display error message on Editor or EditorFor -