could you please tell me how I (a Linux-User) can add text to the last line of a text-file?
I have this so far:
APPEND='Some/Path which is/variable'
sed '${s/$/$APPEND/}' test.txt
It works, but $APPEND is added insted of the content of the variable. I know the reason for this is the singe quote (') I used for sed. But when I simply replace ' by ", no text gets added to the file.
Do you know a solution for this? I don't insist on using sed
, it's only the first command line tool that came in my mind. You may use every standard command line program you like.
edit: I've just tried this:
$ sed '${s/$/'"$APPEND/}" test.txt
sed: -e Ausdruck #1, Zeichen 11: Unbekannte Option für `s'
Append Text Using >> Operator For example, you can use the echo command to append the text to the end of the file as shown. Alternatively, you can use the printf command (do not forget to use \n character to add the next line).
But, if you would like to add some text to the file, you can type in after this, like this: cat >> new. txt This is some text in the file from command line. To stop editing and saving in the file, simply type CTRL+C, it will create, save and exit the file.
echo "$(cat $FILE)$APPEND" > $FILE
This was what I needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With