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?

asked Jun 17, 2015 by Eric Z Ma (44,280 points)

1 Answer

 
Best answer

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

answered Jun 17, 2015 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...