Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

open 100 files in vim

I need to grep to tons (10k+) of files for specific words. now that returns a list of files that i also need to grep for another word.

i found on that grep can do this so i use:

grep -rl word1 *

which returns the list of files i want to check. now from these files (100+), i need to grep another word. so i have to do another grep

vim `grep word2 `grep -rl word1 *``

but that hangs, and it does not do anything,

why?

like image 533
Giraldo Avatar asked Dec 16 '11 15:12

Giraldo


People also ask

How do I open multiple files in Vim?

Ctrl-W w to switch between open windows, and Ctrl-W h (or j or k or l ) to navigate through open windows. Ctrl-W c to close the current window, and Ctrl-W o to close all windows except the current one. Starting vim with a -o or -O flag opens each file in its own split.

How do I open a file in Vim?

Open a new or existing file with vim filename . Type i to switch into insert mode so that you can start editing the file. Enter or modify the text with your file. Once you're done, press the escape key Esc to get out of insert mode and back to command mode.


2 Answers

Because you have a double `, you need to use the $()

vi `grep -l 'word2' $(grep -rl 'word1' *)`

Or you can use nested $(...) (like goblar mentioned)

vi $(grep -l 'word2' $(grep -rl 'word1' *))
like image 71
Book Of Zeus Avatar answered Sep 21 '22 21:09

Book Of Zeus


grep -rl 'word1' | xargs grep -l 'word2' | xargs vi

is another option.

like image 24
Michael Krelin - hacker Avatar answered Sep 22 '22 21:09

Michael Krelin - hacker