将文件分类到多个子目录中的新文件中
Cat files into a new files in multiple sub directories
我希望能够找到文件夹中的子目录
然后在每个子文件夹中找到 .txt 文件
然后将每个子文件夹中的这些文件 CAT 到该文件夹中的新 .txt 文件中。
这是我现在正在使用的,但它不起作用:
找到。 -type d -exec find .{} -type f -iname .txt \; -exec cat {} >> all.txt \;
任何帮助将不胜感激。
谢谢
B
使用 Bash for 循环,这应该有效:
for sub_dir in $(find ./ -type d -not -name '.'); do
cat $sub_dir/*.txt > $sub_dir/all.txt;
done
使用 find 找到的所有子目录(不包括 . 目录)并在每个子目录上发布一个 cat。
找到。 -name "*.txt" -type f -exec cat {} + > all.txt
我希望能够找到文件夹中的子目录 然后在每个子文件夹中找到 .txt 文件 然后将每个子文件夹中的这些文件 CAT 到该文件夹中的新 .txt 文件中。
这是我现在正在使用的,但它不起作用:
找到。 -type d -exec find .{} -type f -iname .txt \; -exec cat {} >> all.txt \;
任何帮助将不胜感激。
谢谢 B
使用 Bash for 循环,这应该有效:
for sub_dir in $(find ./ -type d -not -name '.'); do
cat $sub_dir/*.txt > $sub_dir/all.txt;
done
使用 find 找到的所有子目录(不包括 . 目录)并在每个子目录上发布一个 cat。
找到。 -name "*.txt" -type f -exec cat {} + > all.txt