Yet another awk question.
Can anyone explain why when i run awk below I get the entire 1st line? Ultimately I'm going to have a list of reverse DNS looked up items that I'm going to use to identify what's in a switch.
Sorry if this should go elsewhere. I know this is something obvious... So obvious I think the newbie forum is appropriate. For you newbies, this is more on the business side of linux. i have a list of mac addresses with IP addresses that I just wanted to reverse look-up. Easy-peasy once you know how to use pipes. [root@vnb01 arp]# head 10.15.61.0.macs 10.15.61.1,00:00:0C:07:AC:0A 10.15.61.3,00:E0:86:02:DD:C8 10.15.61.4,00:11:43:88:8E:88 10.15.61.5,00:A0:A5:4B:18:0C 10.15.61.6,00:A0:98:11:5C:08 10.15.61.7,00:05:1E:02:20:74 10.15.61.8,00:60:2E:01:E8:C3 10.15.61.9,00:60:2E:01:E8:B0 10.15.61.10,00:0F:1F:F9:2F:F3 [root@vnb01 arp]# cat 10.15.61.0.macs|awk '/,/ {FS=",";print $1}'|head 10.15.61.1,00:00:0C:07:AC:0A 10.15.61.3 10.15.61.4 10.15.61.5 10.15.61.6 10.15.61.7 10.15.61.8 10.15.61.9 10.15.61.10 10.15.61.11 [root@vnb01 arp]# |
Sure. You've defined FS after $0 has been set to the first line.
Try Code:
awk -F ',' '/,/{print $1}' 10.15.61.0.macs|head |
Quote:
Proof kiddies that you never know it all and you never will. 8) But oh, what a noble goal. Its like academic ADD. Well done, Trenholme. So apparently $0, $1, etc. get set sooner than I thought. |
I am guessing there are other lines in the file that do not have the separator in them otherwise the /,/ is pointless.
I would add though that you could also dispense with head as well: Code:
awk -F, 'NR>10{exit}/,/{print $1}' 10.15.61.0.macs |
I'd also add that you could consider a few other options as well.
Code:
sed -n '1,10 { s/,.*//p }; 11 Q' 10.15.61.0.macs Code:
(( n++ <=5 )) && array+=( "$line" ) || break |
All times are GMT -5. The time now is 01:44 PM. |