i am doing some exercies in vim and i have a problem. I need to find a piece of text in another file in the same directory with my vim file. I used grep to find it but i had an error."bad situation" What i need to use to force grep to go out of vim file and search in "index.html" file ? Here is my grep code:

i = ${grep data-buying index.html | grep USD | grep -oh '[0-9].[0-9]*' | head -n 1}

What is wrong here ?

  • 1
    "... but i had an error." - Any particular error? Or one of those other errors that definitely wouldn't help people answer your question? – Useless Apr 27 '17 at 16:33

Try :read !grep data-buying index.html | grep USD | grep -oh '[0-9].[0-9]*' | head -n 1.

:read !command will run command and standard output will be read into the current buffer at the cursor's location.

  • It didn't work. :( Colon at the beginning is refers to bash command ?(im newbie here sorry :D ) If it is, i wrote that code sample in the vim, file name is blabla.sh. But i tried also in vim it didnt work. – Bysalyanman Apr 27 '17 at 16:11
  • The colon indicated you are sending vim into command mode by typing a colon, which provides a colon prompt. You will then type read !command to execute command and import standard output into your current buffer as described. – DopeGhoti Apr 27 '17 at 16:28
  • I tried it either. It didnt work. it gives read : '!grep' :not a valid identifier. – Bysalyanman Apr 27 '17 at 16:43
  • Unable to replicate. – DopeGhoti Apr 27 '17 at 17:41
  • Try to run the same command but with full path of binaries like ":read !/usr/bin/grep data-buying index.html | /usr/bin/grep USD | /usr/bin/grep -oh '[0-9].[0-9]*' | /usr/bin/head -n 1" – LittleSmurfie Apr 27 '17 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.