【发布时间】:2021-09-09 06:32:11
【问题描述】:
我有一些带有 .txt 和其他扩展名(如 .py、.html)的文件夹和子文件夹,我想将所有文件夹和子文件夹连接到一个 .txt 文件中
我试试这个:
find . -type f -exec cat {} + > test.txt
输入:
txt1.txt:
aaaaa
test.py
print("a")
htmltest1.html:
<head></head>
输出:
aaaaaprint("a")<head></head>
期望的输出:
aaaaa
print("a")
<head></head>
那么,如何修改这个 bash-command 以获得我想要的输出?我想在每个打印文件后粘贴换行符
【问题讨论】:
-
如果你认为你给
-exec的命令是一个你可以完全控制的脚本——这会有帮助吗?find . -type f -exec myscript {} + > test.txt- 你知道我要去哪里吗?for file in "$@" ... -
我刚刚尝试了您的 find 命令,它工作正常,除了我指定了一个目录,而不仅仅是
.以避免将 test.txt 本身作为输入。我还尝试了find . -name *.txt -exec cat {} \; >all-cat.txt,它提供了相同的结果。无法复制。 -
可能排除
find:find . -type f ! -name 'test.txt' -exec cat {} + > test.txt中的输出文件,但我无法重现您的输出。可能是文件中的回车。
标签: bash concatenation cat