In Vi "sed" substitute word on a specific line

i need to substitute word on a specific line.
I was able to do it on command line like below but it is not working in vi.
command line like below:

sed -e '8s/table_name/schema.table_name/' file_name.

in vi table_name and schema are my positional parameters that i pass into the
script.

here is what i have in my script.

Sed -e '8s/$table_name/$schema.$table_name/' file_name > file_new

Thank you
PT.

please try this
:8s/table_name/schema.table_name/' file_name

Thank you for reply.

I added to the script as follows.
':8s/$table_name/$schema.$table_name/' file_name > file_new
it has give error.

Leave off the file stuff, I'm guessing your just wanting the substitution intereactively for the buffer currently being edited in vi

so...

From inside of vi the following command should work (assuming you've escaped out of insert mode and are in command mode):

:8s/table_name/schema.table_name/

shell script positional parameters have to be inside double quotes and singe quotes when using the sed.

below is code:

schema_name=1
table_name=2

sed -e '8s/'"$table_name"'/"$schema_name"'.'"$table_name"'/' input_file

:b:

I think you confused all of us with the references to vi when you are not using vi at all.

Your sed command is doing a lot of unnecessary switching between single quotes and double quotes. You can get exactly the same results as the sed command above just using:

sed -e "8s/$table_name/$schema_name.$table_name/" input_file 

With the values you're using in this example, no quotes are needed at all. But if $table_name or $schema_name could expand to strings containing whitespace characters or characters that could have special meaning to the shell if they aren't quoted, the double quotes protect you in that case. The key point is that the shell doesn't expand variables inside single quotes, so you have to use double quotes instead of single quotes if you want sed to see the table_name and schema_name variables expanded in your sed substitute command.