преобразуйте строки в фиксированную длину столбца

Я хотел бы просто взять данный текстовый файл и осуществить максимальную длину столбца, говорят 80. Как может я поворачивать это:

Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.

и превратите его в это:

Four score and seven years ago our fathers brought forth on this continent, a n
ew nation, conceived in Liberty, and dedicated to the proposition that all men 
are created equal.
2
задан 09.04.2017, 14:47

2 ответа

Используйте команду сгиба:

fold -s -w 80 filename

Опустите -s опция, если Вы предпочитаете повреждаться на символьных границах, а не границах слова (на самом деле пробелы).

Я подозреваю, что это не будет работать очень хорошо, если текст будет закодирован в многобайтовом кодировании, таком как UTF-8 (и содержит символы неASCII).

При использовании Windows используйте Cygwin, UnxUtils или GnuWin32 - они, вероятно, включают сгиб.

5
ответ дан 08.12.2019, 05:51
$ fmt --width=80 <<< 'Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.'
Four score and seven years ago our fathers brought forth on this continent,
a new nation, conceived in Liberty, and dedicated to the proposition that
all men are created equal.
0
ответ дан 08.12.2019, 05:51

Теги

Похожие вопросы