How to find files matching a regex and save each result in an array?

result=$(find . -type f -name -regex '\w{8}[-]\w{4}[-]\w{4}[-]\w{4}[-]\w{12}')
echo $result

I tried the above but used a variable and I’m a bit lost.

>Solution :

mapfile -td '' myarray \
< <(find . -type f -regextype egrep \
    -regex '.*/\w{8}-\w{4}-\w{4}-\w{4}-\w{12}' -print0)

# iterate the array in a loop
for i in "${myarray[@]}"; do
    echo "$i"

Assuming you were looking for files matching this regex.

Leave a Reply