I have a main directory and its sub-directories as;
main_directory == main_directory
0001 0102 0203 ... == first order sub_directories
001 002 003 ... == second order sub_directories
I use below command to merge all data.txt files in the second order sub_directories
find path_to_main_directory -name '*data.txt' -exec cat {} + > data_all
However, I see that data_all
file doesn't seem orderly, such as (which I want); 0001/001+0001/002+.... it seems that the order is random.
Is there a way to merge all files orderly?
find . -name '*data.txt' -print0 | sort -z | xargs -0 cat > data_all
– pLumo Sep 19 '18 at 11:55find
in the first place? Doesn’tcat path_to_main_dir/*/*/*data.txt >data_all
sort as needed? – dessert Sep 19 '18 at 12:17printf '%s\0' path_to_main_dir/*/*/*data.txt | xargs -0 cat
– steeldriver Sep 19 '18 at 12:22