[英]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.