How can I add line breaks to a text file?
January 26, 2011 2:20 AM Subscribe
How can I add line breaks to a text file? I'd like to insert line breaks into a text file so that each line of the text is no more than 33 characters, and I want to avoid line breaks inserted in the middle of words. I've seen online tools that add line breaks every X characters exactly, but this results in words cut in half. Is there an easy way to do what I'm hoping for? If I could just set the line length on Gmail, say, to 33 characters and email myself the text, that would be what I'm looking for. Thanks!
posted by surenoproblem to computers & internet (4 answers total) 1 user marked this as a favorite
fmt:fmt -w 33 file.txt > output.txt
The simple Perl one-liner is about the same:
perl -MText::Wrap -e '$Text::Wrap::columns=33;print wrap("","",<>)' foo.txt > output.txt
These commands usually provide ways to set the leading indentation and whether to re-flow the text or just split long lines.
$ fmt -w 33 foo.txt
How can I add line breaks to a
text file? I'd like to insert
line breaks into a text file
so that each line of the text
is no more than 33 characters,
and I want to avoid line breaks
inserted in the middle of
words. I've seen online tools
that add line breaks every X
characters exactly, but this
results in words cut in half. Is
there an easy way to do what
I'm hoping for? If I could just
set the line length on Gmail,
say, to 33 characters and email
myself the text, that would be
what I'm looking for. Thanks!
posted by zengargoyle at 2:34 AM on January 26, 2011 [3 favorites]