how to append a string at the end of a line but also before some n characters

  • List item

how to add some string at the end of the line in a file : But also before 3 charcters .

I tried but ended up by appending at the last of the string .can anyone help me pls

Example :

content :
line1 :a
line2 :bbbb
lin3: vvvvv
line4: cccccc
line5: dd
line6 :rules(‘test’, ‘.*’, [abc,bcd]).

i tried using
sed -i ‘/rules/ s/$/ ***/’ file1.txt

rules(‘test’,[abc,bcd]). ***

But preffered o/p:

Go to Source
Author: yugandhar