Editing in vi - adding words to a line

i have lines in a file similar to this:

results=$(echo Total: ${res} | command | command)

now I need to add text before the word "results", but i dont know how to do it.

here's what i tried:

%s~results=.*echo Total:.* ${7}~PROCESS \; results=.*echo Total:.* ${7}~g

the problem is, when i run this command in vi, it results in the entire line being modified to reflect the ".*" that i put in there. but that is not what i want.

i'm trying to tell vi how to recognize the lines i want it to update by specifying the words/text on those lines which I know to be permanent...meaning, they aren't going to change throughout the file. then once those lines are identified, i want vi to simply add the text

PROCESS ;

in front of the word results.

OS: Linux/SunOS

& will expand to matched string so you can use:

%s~results=.*echo Total:.* ${7}~PROCESS &~g
1 Like