[Gllug] issues with awk

dudes dudes akam123 at hotmail.co.uk
Mon Sep 12 07:32:00 UTC 2011


Hello, 

Can kindly someone give me some inputs with an awk issue :

I have a dummy file that looks like this:

127.0.0.1 127.0.0.3
1.2.3.4   127.0.0.3
127.0.0.1 1.2.3.4
1.2.3.4   127.0.0.1
23.4.5.11 127.0.0.1
127.0.0.1 1.1.1.1
127.0.0.1 2.2.2.2
127.0.0.1 3.3.3.3
127.0.0.2
127.0.0.1 127.0.0.1
127.0.0.1 127.0.0.1

when I issue the following via the command line: 

root at darkstar:~/r# awk '$1=="127.0.0.1" {print}' test.txt

I get these results and this is what I'm looking for (correct answer):

127.0.0.1 127.0.0.3
127.0.0.1 1.2.3.4
127.0.0.1 1.1.1.1
127.0.0.1 2.2.2.2
127.0.0.1 3.3.3.3
127.0.0.1 127.0.0.1
127.0.0.1 127.0.0.1

However; if I script this in bash such as:

ip="127.0.0.1"

awk '$1==$ip {print}' test.txt

I never get the right results. 

thanks very much for any suggestions or help

ak
 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20110912/18e46fa7/attachment.html>
-------------- next part --------------
--
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug


More information about the GLLUG mailing list