I need to grab the first lines of a long text file for some bugfixing on a smaller file (a Python script does not digest the large text file as intended). However, for the bugfixing to make any sense, I really need the lines to be perfect copies, basically byte-by-byte, and pick up any potential problems with character encoding, end-of-line characters, invisible characters or what not in the original txt.
I think it is no problem for a text file to end mid-line, so copying some specific bytesize would accomplish what I intend to do. Both
dd seem to be able to do this, but
man head says to work on text files and
man dd to copy the standard input to the standard output (and offer conversion tools), I could not verify that they do the copy bit-to-bit, without any conversion or loss. Thus the following two solutions seem to work in tests, but I am not sure I am testing them on any possible problem characters. A definitive answer or another preferable solution would be most helpful.
dd if=input.txt of=output.txt bs=256 count=1
head -c 256 input.txt > output.txt
Also see the original, more specific question here.