Given a long string that needs to be displayed with limited text-width, is there a command line tool in *nix that converts the single-line string to a multi-line string with each line being no longer than a given text-width?
For example, given the following string
$ MYSTRING="Call me Ishmael. Some years ago - never mind how long precisely - having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world."
I would like to format somewhat like this:
$ echo $MYSTRING | special-format-command --width=30
Call me Ishmael. Some years ag
o - never mind how long precis
ely - having little or no mone
y in my purse, and nothing par
ticular to interest me on shor
e, I thought I would sail abou
t a little and see the watery
part of the world.
Best Answer
You might try the
fold
command: