I have a string which i need to insert at a specific position in a file :
The file contains multiple semicolons(;) i need to insert the string just before the last “;”
Is this possible with SED ?
Please do post the explanation with the command as I am new to shell scripting
before :
adad;sfs;sdfsf;fsdfs
string = jjjjj
after
adad;sfs;sdfsf jjjjj;fsdfs
Thanks in advance
This might work for you:
The
\(.*\)is greedy and swallows the whole line, the;makes the regexp backtrack to the last;. The\(.*\)make s a back reference\1. Put all together in the RHS of thescommand means insertjjjjjbefore the last;.