Created
March 7, 2018 03:46
-
-
Save herohenu/c02c366e6eba721801bcf4d170b93c85 to your computer and use it in GitHub Desktop.
shell dict 操作,如果有数据则聚合,没有则追加入dict
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| declare -A mydict | |
| count=0 | |
| errstr="000000000000" | |
| while read campid devid needmd5 | |
| do | |
| #计数器获取当前遍历的是多少行 | |
| ((count+=1)) | |
| if [[ $devid =~ $errstr ]] ;then | |
| continue | |
| fi | |
| #dict 把devid当作key,campid当作value | |
| if [ -z "${mydict[$devid]}" ]; then | |
| mydict+=([$devid]="$campid") | |
| else | |
| mydict+=([$devid]+=","$campid) | |
| fi | |
| if [ $needmd5 -eq 1 ]; then | |
| md5devid="`echo -n $devid|md5sum |awk '{print $1}'|tr '[a-z]' '[A-Z]'`" | |
| echo -e "${ md5devid}\t${campid}" >>${result_file} | |
| fi | |
| #文件行遍历完成的时候才会 | |
| if [ $count -eq $total ]; then | |
| for key in $(echo ${!mydict[*]}); do | |
| echo -e "$key\t${mydict[$key]}" >> ${result_file} | |
| done | |
| fi | |
| done < ${result_file}.bak |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment