We need to find files in a directory with name containing a specific string and add them in a list.
Suppose we create list containing files names in a specific directory containing string ABC
.
Tried this one:
file_list=()
str="ABC"
while IFS= read -d $'\0' -r file ; do
file_list=("${file_list[@]}" "$file")
done < <(find . -name "*$str*" -print0)
echo "Files getting appended: ${file_list[@]}"
If the directory contain files:
ABC.txt, ABCD.txt, XYZ.txt, WXYZ.txt
Then expected output of the above snippet should be:
Files getting appended: ABC.txt ABCD.txt
Getting error message in AIX:
find: 0652-017 -print0 is not a valid option.
Got a related post which works for Linux but got no luck in AIX.
Any help will really be appriciated!