awk for循环

 

awk for循环及 uniq 去重,获取数字值;

注:uniq 只针对相邻的重复行去重,所以与sort配合使用。

#uniq_circle.sh
for  item in `grep errors test.txt | awk -F "==" '{print $2}' | sort | uniq `
do
    echo "test:$item"
done


#test.txt
==44444== 2 errors occurred
==11111== 1 errors occurred
==234567== 1 errors occurred
==44444== 1 errors occurred

 

执行结果

[test@linuxcentos7 awktest]$ ./uniq_circle.sh 
test:11111
test:234567
test:44444

 

posted @ 2022-08-12 20:11  huhuahope  阅读(443)  评论(0编辑  收藏  举报