[英]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
继承stdin
从xargs
,所以它的输入被连接到从管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.