Test files › Documents › no-trailing-newline.txt

Text file with no trailing newline

Three lines where the final line has no terminating newline.

↓ Download no-trailing-newline.txt
Filenameno-trailing-newline.txt
FormatTXT
Size19 bytes (19 bytes)
MIME typetext/plain; charset=utf-8
SHA-2563ed32da374e230c6228e132c8c334191759286fee4813e1ed4eba4d9b9366ea7
What this file catchesLine readers that drop the last record, and concatenation logic that glues the final line to the first line of the next file.

Handle it in code

Each snippet below was run against this exact file with Python 3.14.4 and Node 24.15.0 when this page was built, and the output shown is what it printed.

Python

Read the bytes, not text mode, so the line endings survive to be counted. Invisible format characters (category Cf: zero-width spaces, direction overrides, the BOM) are the ones that make two identical-looking strings compare unequal.

import unicodedata

with open("no-trailing-newline.txt", "rb") as f:
    data = f.read()
crlf = data.count(b"\r\n")
lf, cr = data.count(b"\n") - crlf, data.count(b"\r") - crlf
print(f"line endings: {crlf} CRLF, {lf} LF, {cr} bare CR")
print("ends with a newline" if data.endswith(b"\n") else "no newline at the end of the file")
text = data.decode("utf-8")
print(f"longest line: {max(map(len, text.splitlines()), default=0):,} characters")
hidden = sorted({f"U+{ord(c):04X} {unicodedata.name(c, '?')}" for c in text if unicodedata.category(c) == "Cf"})
print("invisible characters:", ", ".join(hidden) if hidden else "none")

Run against this file, it prints: line endings: 0 CRLF, 2 LF, 0 bare CR no newline at the end of the file longest line: 7 characters invisible characters: none

Related guides and tools

Sample TXT and encoding test filesCharacter encodingsVerify its SHA-256

Download & verify

curl -fsSL -o "no-trailing-newline.txt" "https://files.hexaqa.com/text/no-trailing-newline.txt"
curl -fsSL "https://files.hexaqa.com/text/no-trailing-newline.txt" | sha256sum # expect: 3ed32da374e230c6228e132c8c334191759286fee4813e1ed4eba4d9b9366ea7

More documents test files

valid-500pages.pdflatin1.txtline-endings-crlf.txtline-endings-lf.txtutf16be.txtutf16le.txtutf8-no-bom.txtutf8-with-bom.txt

← All Documents files