Linux 板


LINE

※ 引述《angle065 (Fu)》之铭言: : 大家好,小弟有个问题想请教,因为想直接查询出access.log不重复的ip : 查到可以利用这个指令去查 : awk '{tmp[$1]} END {for (i in tmp) print i}' access.log : 这边有个比较不理解的地方想请教各位大大 这边有点取捷径,如果你看不懂的话可以用: awk '{tmp[$1] = 1} END {for (i in tmp) print i}' access.log 这样就会好懂一些。你可以交叉比较: awk '{tmp[$1]} END {for (i in tmp) print tmp[i]}' access.log 你会发现里面全部都是 1。 : 其中的 {tmp[$1]} 这个部分,我理解是把每一行的 第一组文字 : 写入到tmp这个阵列变数中,接着再利用for回圈去呈现重复的文字 : 也确实是让我取得所有不重复的IP : 想请教这个观念是对的吗? : 那想请问tmp[$1],这个是哪一种语言写入阵列的方式呢? : 因为我稍微略懂一点PHP、JS,这样的做法通常是塞给阵列/物件,索引值再用的 : 应该不是写入阵列 不同家的实做不太一样,但因为 POSIX 标准的关系,标准内定义的功能必须实做: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html 在 GNU awk 的 manual 里面是这样写: All arrays in AWK are associative, i.e., indexed by string values. 而在 FreeBSD 上的 awk manual 则是这样说: Array subscripts may be any string, not necessarily numeric; this allows for a form of associative memory. Multiple subscripts such as [i,j,k] are permitted; the constituents are concatenated, separated by the value of SUBSEP (see the section on variables below). 其他家又会有其他的方式,翻 manpage 或是 google 一下通常都会有。 然後补充一下,你的问题我的习惯是: cut -d ' ' -f 1 access.log | sort -u awk '{print $1}' access.log | sort -u 如果只是要看大宗的数量: awk '{print $1}' access.log | sort | uniq -c | sort -n | tail 然後要看现在是哪个王八蛋在打: while true; do clear; date; tail -n 10000 access.log | awk '{print $1}' | sort | uniq -c | sort -n | tail; sleep 1; done 指令用的习惯就好,方法还蛮多的... -- Resistance is futile. https://blog.gslin.org/ & <[email protected]> --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 122.116.104.21 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Linux/M.1568971993.A.266.html
1F:推 hijkxyzuw: 本来想推用 watch ,但後面那串太长了,又有引号。 09/21 14:22







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:BuyTogether站内搜寻

TOP