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
-eoption enables interpretation of backslash escapes. \nrepresents a newline character, ensuring that "New line of text" is added on a new line inexistingfile.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.
