#!/bin/bash
read -p "please input dir and file:" log
#log=/tmp/recalc720.log
#输入日志路径
for i in `cat $log | sort -k 6 | awk '{print $6}' | uniq -c | sed '1d' | awk '{print $2}'`
do
num=`grep $i $log | grep -v 'to '$i | grep -v '[ ]$' | wc -l`
aa=$(awk "BEGIN{srand($RANDOM); print 1+int($num*rand())}")
bb=$aa
while [ "$aa" -eq "$bb" ]
do
bb=$(awk "BEGIN{srand($RANDOM); print 1+int($num*rand())}")
done
grep $i $log | grep -v 'to '$i | grep -v '[ ]$' | sed -n ''$aa'p'
grep $i $log | grep -v 'to '$i | grep -v '[ ]$' | sed -n ''$bb'p'
done
以前专门写的给文件中的内容分类,并随机抽取
最新推荐文章于 2024-06-28 14:49:31 发布