简体   繁体   中英

Open a file using vim from the output of pipe command

I have a list of files in a text file abc.txt . I have to read the nth line from the file and open the file using vim . I have done this but the file at nth line doesn't open :-

sed -n 4p abc.txt | vim -

Trying to get 4th line from abc.txt and opening it using vim .But the output I get is content of file at that particular line number :- 在此处输入图片说明

The right command would be like this:

vim "$(sed -n 4p abc.txt)"

The difference is that this passes the output of sed as the first argument to vim. As a result, Vim will open that file.

In the command you've typed, the output of sed is piped to the standard input of vim. Since you're passing '-' as the argument to Vim, it assumes that the text to edit is what is coming through the standard input. This text is the filename, but not the contents of the file.

Yes I got it . The command is

vim `sed -n 4p abc.txt`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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