We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Filter an Array with Patterns
Filter an Array with Patterns
Sort by
recency
|
149 Discussions
|
Please Login in order to post a comment
using shell parameter expansion,
${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
The last part is horrible, but necessary for the challenge.
readarray -t array echo "${array[@]/*[aA]*/}" | xargs
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'
arr=()
while IFS= read -r line do if [[ "line") fi done
echo "${arr[@]}"