Hi,
I am using add-content to add a new line of text to an existing text file. for example:
add-content -Path .\test.txt -Value "line2"
The problem is that sometimes this text file might be edited manually, and someone forgets to press enter to take the cursor to the next line. Then the above command would add “line2” to the end of the existing text.
text file:
line1line2
If I try to use the following:
add-content -Path .\test.txt -Value "`nline3"
text file:
line1line2
line3
it works if the above scenario occurs, but after that I get a blank line:
add-content -Path .\test.txt -Value "`nline4"
text file:
line1line2
line3
line4
Is there a way to check if there is a new line at the end of the text file or if the end of the text file ends on a line with some text?