gpt4 book ai didi

shell - 从 find 命令输出中删除新行

转载 作者:行者123 更新时间:2023-12-01 10:47:04 24 4
gpt4 key购买 nike

我想在一个命令中将 find 命令的输出与我的脚本之一一起使用。

我的脚本接受:

some-script --input file1.txt file2.txt file3.txt --output final.txt

我要换 file1.txt file2.txt file3.txt使用`find 命令。
some-script --input `find ./txts/*/*.txt` --output final.txt

但这会中断,因为 find 命令的输出中有新行。

最佳答案

Find 可以输出空格分隔的结果列表,而无需依赖其他命令:

find . -name someFile -type f -printf "%p "

上面会在当前目录或任何子目录中找到所有名为“someFile”的文件,然后打印结果,不换行。

例如,给定这个目录树:
.../dir1/someFile.txt
.../dir1/dir2/someFile.txt

运行 find . -name '*.txt' -type f -printf "%p "从 dir1 将输出:
someFile.txt ./dir2/someFile.txt

传递给上述 find 的参数、选项和“操作”(即 -printf)命令可以修改如下:
  • 如果你不给 -type f选项,find将报告名为 someFile 的所有类型的文件系统条目.此外,find的手册页列出了可以提供给 -type 的其他参数这将导致 find仅搜索目录、仅搜索可执行文件或仅搜索链接等...
  • 更改 -printf "%p "-printf "%f "打印没有路径的文件名,或者再次查看 find find 的其他格式规范的手册页的 printf行动接受。
  • 更改 .到其他目录路径以搜索其他目录树。
  • 关于shell - 从 find 命令输出中删除新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24954253/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com