linux - bash,如何将标准输出到文件

标签 linux bash grep

如何从 BASH 脚本强制将查询输出到文件中?

我试过了

 >  file.txt
| >> file.txt

还有一些

我一直在吐出语法错误,或者根本无法工作。

find fixed/pdf/ -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color "Ascend"' \; | 2>&1 dump.txt

最佳答案

您可以使用:

find fixed/pdf/ -name '*.pdf' -exec sh -c 'pdftotext "$1" - |
   grep --with-filename --label="$1" --color "Ascend"' - '{}' \; > dump.txt 2>&1

将 stdout 和 stderr 重定向到您的文件 dump.txt

关于linux - bash,如何将标准输出到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32681911/

相关文章:

shell - 如何使用 grep 将 stdout 拆分为 stdout 和 stderr?

c++ - 访问文件和打开文件有什么区别

php - 使用特定版本的 PHP 进行 xDebug

unix - 如何将水平输入更改为垂直输出

bash - 将函数存储在 bash 数组元素中

bash - bash 函数可以在不同的脚本中使用吗?

bash - 使用 grep 查找整个字符串

php - 上传文件上的 Finfo_file 以确定 mime 类型

linux - 使用 rtnetlink 套接字在 linux 路由表中安装新路由

python - 我如何通过终端 Linux 向程序发出特定命令?