awk '{print $1}' ios-example.com.access | sort | uniq -c | sort -nr
https://pajda.fit.vutbr.cz/ios/ios-19-1-logs/blob/master/ios-example.com.access.log -这是ios-example.com.access
我做了一些东西,它工作了,但并不完全像我想要的那样。有没有人可以帮我升级我的命令?
现在的输出如下所示:
8 192.27.69.191
2 82.202.69.253
输出必须如下所示:
198.27.69.191 (8): ########
82.202.69.253 (2): ##
我甚至需要它的标签
发布于 2019-03-28 02:12:20
cat ios-example.com.access | sort | uniq -c | awk 'ht="#"{for(i=1;i<$1;i++){ht=ht"#"} str=sprintf("%s (%d): %s", $2,$1, ht); print str}'
需要包含如下内容的文件:
ipadress1
ipadress1
ipadress1
ipadress2
ipadress2
ipadress1
ipadress2
ipadress1
发布于 2019-03-28 01:26:06
您可以通过向列表中添加另一个awk
来升级您的命令,或者您可以只使用一个awk来完成所有操作:
awk '{a[$1]++}
END { for(i in a) {
printf "%s (%d):" ,i,a[i]
for(j=0;j<a[i];++j) printf "#"; printf "\n"
}
}' file
发布于 2019-03-28 01:57:09
将xargs
与sh
和printf
一起使用。字里行间的注释。tutorialspoint上的实况版本。
# sorry cat
cat <<EOF |
8 192.27.69.191
2 82.202.69.253
EOF
# for each 2 arguments
xargs -n2 sh -c '
# format the output as "$2 ($1): "
printf "%s (%s): " "$2" "$1"
# repeat the character `#` $1 times
seq "$1" | xargs printf "#%.0s"
# lastly a newline
printf "\n"
' --
我认为我们可以通过以下方式缩短这段时间:
xargs -n2 sh -c 'printf "%s (%s): %s\n" "$2" "$1" $(printf "#%.0s" $(seq $1))' --
或者,如果输入足够安全,也可以只使用echo:
xargs -n2 sh -c 'echo "$2 ($1): $(printf "#%.0s" $(seq $1))"' --
https://stackoverflow.com/questions/55382420
复制相似问题