how to add text into the last line of text file

I need help with insert text to the last line of text file with echo command

I know can do something like

echo "i4\n$logtext\n.\nwq" | ex -s $file

can insert to first line, but how can i change this code in order to insert to the last line of text file?

please help, thank you :frowning:

Remove the 4 and check for yourself.

1 Like

Try like...

echo "i4\n$logtext\n.\nwq" >>test1.txt