Result of a normal find using find . ! -path "./build*" -name "*.txt"
:
./tool/001-sub.txt
./tool/000-main.txt
./zo/001-int.txt
./zo/id/002-and.txt
./as/002-mod.txt
and when sorted with sort -n
:
./as/002-mod.txt
./tool/000-main.txt
./tool/001-sub.txt
./zo/001-int.txt
./zo/id/002-and.txt
however the desired output is:
./tool/000-main.txt
./zo/001-int.txt
./tool/001-sub.txt
./zo/id/002-and.txt
./as/002-mod.txt
which means output is sorted based on filename only, but folder information should be maintained as part of the output.
Edit: Make example more complicated as the subdirectory structure may include more than one level.
-printf
instead ofawk
), I think that is the best solution. I've reworked my original implementation to use this method.