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

Similar Posts

  • |

    git push error

    $ git push error: The requested URL returned error: 403 Forbidden while accessing https://github.com/HarryWei/hummer.git/info/refs fatal: HTTP request failed Replace (or add) url=ssh://git@github.com/HarryWei/hummer.git with url=https://git@github.com/HarryWei/hummer.git under “[remote “origin”]” section in ~/.gitconfig file. Reference:http://stackoverflow.com/questions/7438313/pushing-to-git-returning-error-code-403-fatal-http-request-failed Read more: Git push error under CENTOS 6.7 Push and Pull data from Restful Service in Asp.net MVC Application using Angular JS Fixing…

  • |

    Vim Indenting C/C++ Code

    Vim provides some basic formatting commands. A combination of these commands with the editing commands will make the programmer happy. A list of basic text formatting commands in Vim: = is an operator that formats/indents text. i{ is a text object that specifies the surrounding code block. It should be used together with v, =,…

Leave a Reply

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