0

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?

deepblue_86
  • 1,194
  • Use find . -name '*data.txt' -print0 | sort -z | xargs -0 cat > data_all – pLumo Sep 19 '18 at 11:55
  • Why do you use find in the first place? Doesn’t cat path_to_main_dir/*/*/*data.txt >data_all sort as needed? – dessert Sep 19 '18 at 12:17
  • @dessert it may fail if the argument list is too long - but there are ways around that e.g. printf '%s\0' path_to_main_dir/*/*/*data.txt | xargs -0 cat – steeldriver Sep 19 '18 at 12:22

0 Answers0