How can I automatically open a file if this is the only result in grep?

[meder@kat directoryName]$ grep -RlI "send you instr" *
application/views/scripts/auth/forgot.phtml
[meder@kat directoryName]$

Is there a quick hack to link to a single result? Can I somehow connect it to vim?

+3
source share
3 answers

If you're fine with opening all the results in Vim, you can simply do:

vim $(grep -RlI "send you instr" *)

You will be buffered with the first matching file and you can switch to others using :next.

+4
source

Open a new file in vim and paste the found file name as text:

grep -RlI "send you instr" * | vim -

Open the found file directly in vim:

grep -RlI "send you instr" * | xargs vim
+3
source
vim `grep -RlI "send you instr" *`
+1

Source: https://habr.com/ru/post/1769227/


All Articles