Monday, January 29, 2024

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

Issue

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'


Answered By - romainl
Answer Checked By - David Marino (WPSolving Volunteer)