Count length of element in array


  • 0
    A

    #!/bin/bash
    declare -A HW
    File=words.txt
    while read line
    do
    word=${line[*]}
    for var in ${word[ * ]}
    do
    HW[$var]=${HW[$var]}'1'
    done
    done < $File

    for key in ${!HW[*]}
    do
    echo "${key} ${#HW[$key]}"
    done


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.