長い文字列に改行を挿入するコマンドラインツールはありますか?

長い文字列に改行を挿入するコマンドラインツールはありますか?

限られたテキスト幅で表示する必要がある長い文字列がある場合、単一行文字列を複数行文字列に変換できるコマンドラインツールは* nixにありますか?各行は、指定されたテキストの幅より長くありません。

たとえば、次の文字列が与えられた場合

$ 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."

次の形式が必要です。

$ 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.

ベストアンサー1

次のfoldコマンドを試すことができます。

echo "$MYSTRING" | fold -w 30

おすすめ記事