I have an array containing a list of file paths within different levels of directories. I want to filter that array to only files,meaning those that end with an /
should remain in the array. All paths are no real paths on my file system I could check the type using OS tools for directories/files.
I have an array with following strings:
file-a
dir/
dir/file-b
dir/dir-2/
dir/dir-2/file-c
And want to filter it to the following strings (no directories):
file-a
dir/file-b
dir/dir-2/file-c
I tried it with the following but that removes all paths including a /
, resulting in file-a
being the only remain.
FILES_ARRAY=( ${FILES_ARRAY[@]//*\/} )
I tried to add an $
(as common in regex syntax) to denote the end which does not remove anything from the array.
FILES_ARRAY=( ${FILES_ARRAY[@]//*\$/} )