Your requirements and your example don't match. Putting the tilde after the newline would make it the first character on the second line, not the last character on the first line.
Code:
test|123|abcd
te12|258|abdk
would become
Code:
test|123|abcd
~te12|258|abdk
~