$ cat shxp.txt
O, they have lived long on the alms-basket of words, I marvel thy
master hath not eaten thee for a word; for thou art not so long by the
head as honorificabilitudinitatibus: thou art easier swallowed than a
flap-dragon.
1) Assured fixed line width with word breaking:
fold -w 20 <shxp.txt
O, they have lived l
ong on the alms-bask
et of words, I marve
l thy master hath no
t eaten thee for a w
ord; for thou art no
t so long by the hea
d as honorificabilit
udinitatibus: thou a
rt easier swallowed
than a flap-dragon.
2) Assured fixed line width with extraordinary word breaking. A word gets broken only if it is too large to fit in a line:
fold -sw 20 <shxp.txt
O, they have lived
long on the
alms-basket of
words, I marvel thy
master hath not
eaten thee for a
word; for thou art
not so long by the
head as
honorificabilitudini
tatibus: thou art
easier swallowed
than a flap-dragon.
3) Promising fixed line width without any word breaking. If word is too large to fit in a line, it is still left as it is, so finally some lines may be larger in size than you need:
fmt -w 20 <shxp.txt
O, they have
lived long on the
alms-basket of
words, I marvel
thy master hath
not eaten thee
for a word; for
thou art not so
long by the head as
honorificabilitudinitatibus:
thou art easier
swallowed than
a flap-dragon.
Note that fmt
also tries to balance ragged paragraph lines unlike fold -s
.