get first X characters from the cat command?

head -c 50 file

This returns the first 50 bytes.

Mind that the command is not always implemented the same on all OS. On Linux and macOS it behaves this way. On Solaris (11) you need to use the gnu version in /usr/gnu/bin/


Your cut command works if you use a pipe to pass data to it:

cat ${file} | cut -c1-50 

Or, avoiding a useless use of cat and making it a little safer:

cut -c1-50 < "$file"

Note that the commands above will print the first 50 characters (or bytes, depending on your cut implementation) of each input line. It should do what you expect if, as you say, your file is one huge line.


dd status=none bs=1 count=50 if=${filename}

This returns the first 50 bytes.

Tags:

Cut

Cat