Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
awk命令-定义单词的大小_Awk - Fatal编程技术网

awk命令-定义单词的大小

awk命令-定义单词的大小,awk,Awk,我正在学习AWK,并试图计算到特定目的地的会话数 使用此命令: awk '{print $9}' traffic-log-cust.txt | sort | uniq -c 我得到下面的输出 #awk '{print $9}' traffic-log-cust.txt | sort | uniq -c 1 1 10.10.17.72/38403->157.55.235.140/40046 1 10.10.17.72/38403->157.55.

我正在学习AWK,并试图计算到特定目的地的会话数

使用此命令:

awk '{print $9}' traffic-log-cust.txt | sort | uniq -c
我得到下面的输出

#awk '{print $9}' traffic-log-cust.txt | sort | uniq -c
      1 
      1 10.10.17.72/38403->157.55.235.140/40046
      1 10.10.17.72/38403->157.55.235.146/40006
      1 10.10.17.72/38403->157.55.235.148/40039
      1 10.10.17.72/38403->157.55.235.159/40019
      1 10.10.17.72/38403->157.55.235.160/40019
      1 10.10.17.72/38403->157.55.56.156/40046
      1 10.10.17.72/38403->157.55.56.174/40018
      1 10.10.17.72/38403->64.4.23.156/40017
      1 10.10.17.72/38403->64.4.23.164/40011
      1 10.10.17.72/38403->64.4.23.166/40053
      1 10.10.17.72/38403->65.55.223.16/40003
      1 10.10.17.72/38403->65.55.223.44/40002
#
我相信word 9没有空间,也包含目标IP

我想知道如何根据目标IP计算会话数


提前谢谢

我想你在决定每个领域的规模时会遇到一些问题。(你的问题不清楚。)我认为你不需要;只需将每行分成两个字段,然后处理第二个字段

使用awk,您可以使用-F选项指定分隔符是什么,并且由于大于号(>)在许多shell中都有意义,因此您必须以某种方式对其进行转义。在Linux中,可以使用反斜杠

由于您使用的是
awk
,因此不需要
sort
uniq
;可以使用关联数组

假设您没有忽略端口:

awk -F\> '{dest_ips[$2]++} 
           END {
             for (ip in dest_ips) {
               printf "%s: %d\n", ip, dest_ips[ip]
             }
          }' traffic-log-cust.txt

如果忽略端口,则必须首先解析第二个字段(可能使用
split()
)。

请在问题中添加示例输入和该示例输入的所需输出。预期输出是什么?