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