How to append to a new line?

0127

To append text to a new line in a file using the >> operator, you can include a newline character before the text. Here’s how you can do it:

echo -e "\nNew line of text" >> existingfile.txt

In this command:

  • The -e option enables interpretation of backslash escapes.
  • \n represents a newline character, ensuring that "New line of text" is added on a new line in existingfile.txt.

Alternatively, you can also use:

echo "New line of text" >> existingfile.txt
echo "" >> existingfile.txt

This will first append an empty line and then the new text, effectively placing it on a new line.

0 Comments

no data
Be the first to share your comment!