Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux bash,如何标准输出到文件_Linux_Bash_Grep - Fatal编程技术网

Linux bash,如何标准输出到文件

Linux bash,如何标准输出到文件,linux,bash,grep,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/pd

如何从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

而不是
|2>&1 dump.txt
请尝试
>dump.txt 2>&1
@doh
找到fixed/pdf/-name'*.pdf'-exec sh-c'pdftotext'{}“-grep--文件名为--label=“{}”--color“Ascend”\在没有重定向的情况下生成?请注意,
{}
不应该以这种方式使用!这是非常不安全的,并使命令受制于代码注入。对于将近300k的rep,您还应该提到这一点,并展示如何正确使用
{}
。此外,它也是错误的,正如POSIX所指定的:如果一个实用程序名称或参数字符串包含两个字符“{}”,而不仅仅是两个字符“{}”,那么find是否替换这两个字符或使用该字符串而不作任何更改是由实现定义的。