Sort by

recency

|

149 Discussions

|

  • + 0 comments
    while read input
    do
        my_arr=("${my_arr[@]}" $input)
    done
    
    pattern=(${my_arr[@]/*[aA]*/})
    echo "${pattern[@]}"
    
  • + 0 comments

    using shell parameter expansion,

    mapfile countries
    echo ${countries##*[Aa]*}
    

    ${parameter##pattern} deletes longest matching pattern.

    If you need further information, here is bash reference manual. https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion

  • + 0 comments
    mapfile -t array
    
    output=$(grep -vi "a" <(printf "%s\n" "${array[@]}"))
    
    if [ -z "$output" ]; then
     echo ""
    else
     echo "$output"
    fi
    

    The last part is horrible, but necessary for the challenge.

  • + 0 comments

    readarray -t array echo "${array[@]/*[aA]*/}" | xargs

    1. elements in the array that containing 'a' or 'A', will be replaced by ' '(space).
    2. xargs command trims leading and trailing spaces

    another approach: readarray -t array printf '%s\n' "${array[@]}" | grep -Ev "a|A"

    here printf prints each array element in a new line, The grep command here filters out 'a' or 'A'

  • + 1 comment

    arr=()

    while IFS= read -r line do if [[ "line") fi done

    echo "${arr[@]}"