find /.example1 -name example*.txt" -type f -exec| mvawk -F\/ '{}' for(i=1;i<=NF-1;i++) { path=path$i"/.example1" } } END { print "mv "$0" "path"folder/folder"$NF \;}' | sh Do a find on all the example files in the directory and then executeparse the returned output using awk, forming a move command. that is executed with sh