简体   繁体   English

按数字升序组合同名但在不同目录中的文件

[英]Combine files of same name, but in different directories, in numerically ascending order

I need to combine files (of same name) present in different directories (like traj_1/ traj_2/ etc.) to a single file, but as per the numerically ascending order of the directories.我需要将不同目录(如 traj_1/traj_2/ 等)中存在的文件(同名)组合到一个文件中,但要按照目录的数字升序排列。

Attempts like:尝试如下:

cat $(find./ -name "/homes/epsilon/users/diem/project_tau43_Ab42/tau43_monomer/traj_*/production/3D-RISM/thm_decomposition/thma_vs_time/xmu_data/xmu_res_001_vs_time.dat" | sort -V) > diem/alltraj_Gsolv_res1.dat cat $(find./ -name "/homes/epsilon/users/diem/project_tau43_Ab42/tau43_monomer/traj_*/production/3D-RISM/thm_decomposition/thma_vs_time/xmu_data/xmu_res_001_vs_time.dat" | sort -V) > diem/alltraj_Gsolv_res1 .dat

cat $(find./ -wholename /homes/epsilon/users/diem/project_tau43_Ab42/tau43_monomer/traj_*/production/3D-RISM/thm_decomposition/thma_vs_time/xmu_data/xmu_res_001_vs_time.dat" | sort -V) > diem/alltraj_Gsolv_res1.dat猫$(查找。/-wholename /homes/epsilon/users/diem/project_tau43_Ab42/tau43_monomer/traj_*/production/3D-RISM/thm_decomposition/thma_vs_time/xmu_data/xmu_res_001_vs_time.dat”|排序-V)> diem/alltraj_Gsolv_res1。数据

are not working out没有工作

Any suggestions will be deeply appreciated, thanks in advance.任何建议将不胜感激,在此先感谢。

find . -name "*new.txt" | awk -F/ '{ fil[$NF]+=1;fil1[$NF][$0]="" } END { for (i in fil) { if ( fil[i] > 1) { for (j in fil1[i]) { printf "%s ",j }  printf "\n" } } }'

The above script will show all files with the same name in the directory structure displayed on single lines for each entry.上面的脚本将在每个条目的单行显示目录结构中显示所有具有相同名称的文件。 Piping the output through to xargs and cat will then print a merged version of the files:将 output 通过管道连接到 xargs,然后 cat 将打印文件的合并版本:

find . -name "*new.txt" | awk -F/ '{ fil[$NF]+=1;fil1[$NF][$0]="" } END { for (i in fil) { if ( fil[i] > 1) { for (j in fil1[i]) { printf "%s ",j }  printf "\n" } } }' | xargs cat

Explanation:解释:

find . -name "*new.txt" | awk -F/ 
'    { 
        fil[$NF]+=1; # Take the file name and create an array with an incrementing 
                       value for each file name observed.
        fil1[$NF][$0]="" # Create a 2 dimentional array with the file name as the 
                           first index and the full path as the second
     } 
 END { 
        for (i in fil) { # Loop through the entries in the fil array
           if ( fil[i] > 1) { # If there is more than one entry (entries with the same 
                                file name) process.
               for (j in fil1[i]) { 
                 printf "%s ",j # Print the full path
               }  
               printf "\n" 
           } 
         } 
      }'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查名称相同但扩展名不同的目录中的文件 - How to check files in different directories with same name but different extensions 如何从多个目录中提取多个文件,而不同目录中的不同文件可能具有相同的名称 - how to scp multiple files from multiple directories, while different files in different directories may have the same name 如何使用find重命名具有相同名称的不同目录中的文件 - How to rename files in different directories with the same name using find 在不同目录中查找具有相同名称的文件并计算重复项 - find files with same name in different directories and count duplicates 连接不同目录中同名文件的更快方法 - Faster way to concatenate files of same name in different directories 在两个主目录中查找具有相同名称和子目录但内容不同的文件 - Finding the Files with the Same Name and Sub-Directories But Different Contents in Two Main Directories zgrep 文件按升序排列 - zgrep files in ascending order 如何使用Meld比较不同目录中的两个相同名称文件(不提供其路径)? - How to compare two same name files in different directories using meld (without giving their path)? 不同文件夹中具有相同名称的文件 - files with same name in different folders 将多个目录中的多个文件从服务器复制到本地,文件进入与服务器同名的目录 - Copying multiple files in multiple directories from server to local, with files going into directories with the same name as server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM