Given a text file, or the output of a command, how can I truncate it so that every line longer than N characters (usually N=80 in a terminal) gets shorten to N characters maximum?


You can use cut to achieve this (using N=80 here):

some-command | cut -c -80


cut -c -80 some-file.txt

Replace 80 with the number of characters you want to keep.

Multi-bytes characters may not be handled correctly, depending on your implementation.

  • 3
    The equivalent form cut -c 1-80 may be better for understanding. – Libin Wen Oct 28 '19 at 10:57
  • fixed command syntax you must supply a range: "some-command | cut -c 1-80" – berhauz Jan 27 at 9:43
  • Without the 1 it's easy to miss the - before the 80 so I agree it makes more sense. – Sridhar Sarnobat Feb 5 at 1:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.