Scottt
Scottt

Reputation: 185

Using the output of one command as the argument for another

I am attempting to grep a file and pipe the line number out to

vim +{lineNumber} filetoedit

unfortunately Vim throws an error saying

Vim: Warning: Input is not from a terminal

An example:

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

Upvotes: 1

Views: 85

Answers (1)

Barmar
Barmar

Reputation: 780851

The command run by xargs inherits stdin from xargs, so its input is connected to the pipe from cut, not the terminal.

Assign the result to a variable and use that.

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

Upvotes: 3

Related Questions