How to wrap long lines in a text file on Linux?

I have some text files which contain some long lines. Now I would like to break lines to at most 80 characters. How to wrap long lines in a text file on Linux?

The fold command can wrap lines.

fold – wrap each input line to fit in specified width

For your purpose,

fold -w 80 -c in.txt > out.txt

fold has more options, you may check

-b, –bytes
count bytes rather than columns

-c, –characters
count characters rather than columns

-s, –spaces
break at spaces

-w, –width=WIDTH
use WIDTH columns instead of 80

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *