http://www.gnu.org/software/coreutils/manual/html_node/fold-invocation.html#fold-invocation的文档很明确:
‘--spaces’
Break at word boundaries: the line is broken after the last blank before the maximum line length. If the line contains no such blanks, the line is broken at the maximum line length as usual.
然而,在我的场景中这是不可取的,因为它会破坏文本中的链接和路径。我真的不介意有时会超出长度。
还有其他更强大的折叠版本吗?还是有替代方案吗?
更多信息:这是我的代码,一个简单的功能,用于漂亮打印文本并做一些缩进
fold -s -w $(( $COLUMNS - 4 )) <<< "$1" | sed -e '2,$s/^/ /g'
期望的行为:
COLUMNS=40
输入
this is a text with some quite short and manageble text but also with some loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong words so please dont split the ooooos
输出
this is a text with some quite short and
manageble text but also with some loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
words so please dont split the ooooos
由于