Search code examples
vimsedcommand-linegrep

How to insert line before any line containing a certain string from vim or command line?


I have a file with a bunch of data, for example:

something_id: someId
something_version: someVersion
something_log: someLog

I want to add a line of text before every line containing something_log which says something_test: example1

How would I go about this? Any help would be appreciated!


Solution

  • In Vim, you can use :help :global and :help :put:

    :g/something_log/put!='something_test: example1'