bprasanna
bprasanna

Reputation: 2453

Linux cat command output with new lines to be read using vim

I am trying to open all the files listed in file a.lst:

symptom1.log
symptom2.log
symptom3.log
symptom4.log

But trying the following command:

cat a.lst | tr "\n" " " | vim -

opens only the stdin output

symptom1.log symptom2.log symptom3.log symptom4.log

It doesn't open symptom1.log, symptom2.log, symptom3.log & symptom4.log in vim.

How to open all the files listed in a.lst using vim?

Upvotes: 3

Views: 2580

Answers (3)

ghoti
ghoti

Reputation: 46856

I like a variation on Qiau's xargs option:

xargs vim < a.lst

This works because the input redirection is applied to the xargs command rather than vim.

If your shell is bash, another option is this:

vim $(<a.lst)

This works because within the $(...), input redirection without a command simply prints the results of the input, hence expanding the file into a list of files for vim to open.

UPDATE:

You mentioned in comments that you are using csh as your shell. So another option for you might be:

vim `cat a.lst`

This should work in POSIX shells as well, but I should point out that backquotes are deprecated in some other shells (notably bash) in favour of the $(...) alternative.

Note that redirection can happen in multiple places on your command line. This should also work in both csh and bash:

< a.lst xargs vim

vim may complain that its input is not coming from a terminal, but it appears to work for me anyway.

Upvotes: 2

Qiau
Qiau

Reputation: 6175

You could use xargs to line upp the arguments to vi:

vim $(cat 1.t | xargs)

or

cat a.lst | xargs vim

If you want them open in split view, use -o (horizontal) or -O (vertical):

cat a.lst | xargs vim -o
cat a.lst | xargs vim -O

Upvotes: 6

Laser
Laser

Reputation: 6960

while read f ; do cat $f ; done < a.lst | vim -

Upvotes: 2

Related Questions