如何 cat 从回声管道传输的文件?
How do I cat a file piped from echo?
我希望这会打印 foobar.txt:
的内容
echo "~/sandbox/foobar.txt" | cat
但它只是打印到控制台:
~/sandbox/foobar.txt
如何 cat
文件内容而不是打印文件名?
编辑:这是我实际尝试做的非人为示例:
echo $RESULT \
| grep "check file .*make.err" \
| sed -e "s/.*check file '//" \
| sed -e "s/'.*//" \
| xargs cat
EDIT 2: RESULT 在我的脚本文件中保存了上一个命令的输出。这可能是这样的:
runspec v6152 - Copyright 1999-2008 Standard Performance Evaluation Corporation
Using 'macosx' tools
Reading MANIFEST... 18357 files
Loading runspec modules................
Locating benchmarks...found 31 benchmarks in 6 benchsets.
Reading config file '/Users/<REDACTED>/spec/installation/config/<REDACTED>.cfg'
Benchmarks selected: 400.perlbench
Compiling Binaries
Building 400.perlbench base macosx-ia32-iccifortv101-pgofast-static default: (build_base_macosx-ia32-iccifortv101-pgofast-static.0000)
Error with make 'specmake build': check file '/Users/<REDACTED>/spec/installation/benchspec/CPU2006/400.perlbench/build/build_base_macosx-ia32-iccifortv101-pgofast-static.0000/make.err'
Command returned exit code 2
Error with make!
*** Error building 400.perlbench
If you wish to ignore this error, please use '-I' or ignore errors.
The log for this run is in /Users/<REDACTED>/spec/installation/result/CPU2006.062.log
The debug log for this run is in /Users/<REDACTED>/spec/installation/result/CPU2006.062.log.debug
*
* Temporary files were NOT deleted; keeping temporaries such as
* /Users/<REDACTED>/spec/installation/result/CPU2006.062.log.debug
* (These may be large!)
*
runspec finished at Sat Feb 21 08:40:02 2015; 15 total seconds elapsed
要将标准输入转换为参数,您可以使用 xargs:
echo ~/sandbox/foobar.txt | xargs cat
为防止特殊字符(引号和空格)出现问题,您可以使用 xargs -0
并传入 [=13=]
个分隔文件:
printf "%s[=11=]" ~/sandbox/foobar.txt | xargs -0 cat --
请注意,您不能像在示例中那样对 ~
进行双引号。用用户的主目录替换 ~
是 shell 的工作,如果你双引号它,你抑制它。
如果你想要foobar.txt的内容:
cat ~/sandbox/foobar.txt
或:
cat `echo ~/sandbox/foobar.txt`
这是等效的(但过于复杂)
如果您希望 foobar.txt 的内容被视为要分类的 文件名 个文件,您可以使用:
cat `cat ~/sandbox/foobar.txt`
反引号使内部猫的结果显示为外部猫的参数。大笑猫!
我希望这会打印 foobar.txt:
的内容echo "~/sandbox/foobar.txt" | cat
但它只是打印到控制台:
~/sandbox/foobar.txt
如何 cat
文件内容而不是打印文件名?
编辑:这是我实际尝试做的非人为示例:
echo $RESULT \
| grep "check file .*make.err" \
| sed -e "s/.*check file '//" \
| sed -e "s/'.*//" \
| xargs cat
EDIT 2: RESULT 在我的脚本文件中保存了上一个命令的输出。这可能是这样的:
runspec v6152 - Copyright 1999-2008 Standard Performance Evaluation Corporation
Using 'macosx' tools
Reading MANIFEST... 18357 files
Loading runspec modules................
Locating benchmarks...found 31 benchmarks in 6 benchsets.
Reading config file '/Users/<REDACTED>/spec/installation/config/<REDACTED>.cfg'
Benchmarks selected: 400.perlbench
Compiling Binaries
Building 400.perlbench base macosx-ia32-iccifortv101-pgofast-static default: (build_base_macosx-ia32-iccifortv101-pgofast-static.0000)
Error with make 'specmake build': check file '/Users/<REDACTED>/spec/installation/benchspec/CPU2006/400.perlbench/build/build_base_macosx-ia32-iccifortv101-pgofast-static.0000/make.err'
Command returned exit code 2
Error with make!
*** Error building 400.perlbench
If you wish to ignore this error, please use '-I' or ignore errors.
The log for this run is in /Users/<REDACTED>/spec/installation/result/CPU2006.062.log
The debug log for this run is in /Users/<REDACTED>/spec/installation/result/CPU2006.062.log.debug
*
* Temporary files were NOT deleted; keeping temporaries such as
* /Users/<REDACTED>/spec/installation/result/CPU2006.062.log.debug
* (These may be large!)
*
runspec finished at Sat Feb 21 08:40:02 2015; 15 total seconds elapsed
要将标准输入转换为参数,您可以使用 xargs:
echo ~/sandbox/foobar.txt | xargs cat
为防止特殊字符(引号和空格)出现问题,您可以使用 xargs -0
并传入 [=13=]
个分隔文件:
printf "%s[=11=]" ~/sandbox/foobar.txt | xargs -0 cat --
请注意,您不能像在示例中那样对 ~
进行双引号。用用户的主目录替换 ~
是 shell 的工作,如果你双引号它,你抑制它。
如果你想要foobar.txt的内容:
cat ~/sandbox/foobar.txt
或:
cat `echo ~/sandbox/foobar.txt`
这是等效的(但过于复杂)
如果您希望 foobar.txt 的内容被视为要分类的 文件名 个文件,您可以使用:
cat `cat ~/sandbox/foobar.txt`
反引号使内部猫的结果显示为外部猫的参数。大笑猫!