26

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?

marked as duplicate by jasonwryan, Archemar, Anthon, Stephen Kitt, Community Mar 26 '15 at 11:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

45

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

some-command | cut -c -80

or

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.

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