偷懒,输出前少一步排序

# cat nowcoder.txt | awk '{print $2}' | sort -r | uniq -cd
# awk '{print $2}' nowcoder.txt | sort -r | uniq -cd
# cut -d" " -f2 nowcoder.txt | sort -r| uniq -cd
declare -A map 
function foreach() {
    local tem=""
    for key in ${!map[@]}; do
        tem=${map[${key}]}
        if [ ${tem} -gt 1 ]; then
            echo "${tem} ${key}"
        fi
    done
}

function test2() {
    local temp=""
    for line in `cut -d" " -f2 nowcoder.txt`; do
        temp=${map[${line}]}
        if [ -z "${temp}" ]; then
            map[${line}]=1
        else 
            ((map[${line}]++))
        fi
    done
    foreach
}

function test3() {
    local ele=""
    local arr=""
    while read line; do
        arr=(${line})
        ele=${arr[1]}
        temp=${map[${ele}]}
        if [ -z "${temp}" ]; then
            map[${ele}]=1
        else 
            ((map[${ele}]++))
        fi
    done < nowcoder.txt
    foreach
}

# test2
test3