繁体   English   中英

使用一个命令的输出作为另一个命令的参数

[英]Using the output of one command as the argument for another

我正在尝试grep一个文件并将行号输出到

vim +{lineNumber} filetoedit

不幸的是,Vim发出错误说

Vim:警告:输入不是来自终端

一个例子:

grep -nF 'Im looking for this' testfile.txt | cut -f1 -d: | xargs vim +{} testfile.tx

通过运行该命令xargs继承stdinxargs ,所以它的输入被连接到从管cut ,而不是终端。

将结果分配给变量并使用它。

line=$(grep -nF 'Im looking for this' testfile.txt | cut -f1 -d: )
vim "+$line" testfile.txt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM