Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

网上看到一个用awk打印Ip但是没有IP地址放到引号中的情况,出现了一些奇怪的现象,自己尝试了一些情况如下:

cnbubble@~/test:$ awk 'BEGIN{print 1.1.1.1}'
1.10.10.1
cnbubble@~/test:$ awk 'BEGIN{print 1.1000.1.1}'
1.10.10.1
cnbubble@~/test:$ awk 'BEGIN{print 1.1000.100.1}'
1.10.10.1
cnbubble@~/test:$ awk 'BEGIN{print 1.1000.10000.1}'
1.10.10.1
cnbubble@~/test:$ awk 'BEGIN{print 1.1020.10000.1}'
1.1020.10.1
cnbubble@~/test:$ awk 'BEGIN{print 1.1020.10100.1}'
1.1020.1010.1
cnbubble@~/test:$

大家可尝试更多
最开始以为是awk print的原因,后来把这串数赋值给变量,再打印也是这样,感觉是awk中数据读取原因导致的,它不是数字,但awk可能按照数值的读取把数字的格式变了,例如:

cnbubble@~/test:$ awk 'BEGIN{a=1.300;print a}'
1.3

但为什么awk不报错?它读取数据的原理是什么?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
203 views
Welcome To Ask or Share your Answers For Others

1 Answer

1.1.1.1 => 1.1 | .1 | .1 => 1.1 | 0.1 | 0.1 => 1.10.10.1

以此类推.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...