Unix“;“包装”;滤波器
有吗 我可以用这样的东西:Unix“;“包装”;滤波器,unix,shell,filter,Unix,Shell,Filter,有吗 我可以用这样的东西: $ cat someFileWithLongLines.txt | wrap -80 --indent|less 该命令称为“折叠”,但不支持缩进线条的包装部分。您需要为该命令发出awk。您可能需要该命令 或 该命令称为fold $cat someFileWithLongLines.txt | fold您可以使用awk width=10 awk -vw="$width" '{ i=1 while( length(substr($0,i,w) ) ){
$ cat someFileWithLongLines.txt | wrap -80 --indent|less
该命令称为“折叠”,但不支持缩进线条的包装部分。您需要为该命令发出awk。您可能需要该命令 或
该命令称为fold $cat someFileWithLongLines.txt | fold您可以使用awk
width=10
awk -vw="$width" '{
i=1
while( length(substr($0,i,w) ) ){
print substr($0,i,w)
i+=w
}
}' file
输出:
$ more file
this is a line 1
this is a line 2
$ fold -w 10 file
this is a
line 1
this is a
line 2
$ ./shell.sh
this is a
line 1
this is a
line 2
如果你愿意,你可以用缩进
$ fold -w 76 -s file.txt | pr -T --indent=4
GNU coreutils有一个名为
fmt
的命令:
$ fmt -40 -t lorem
另一种选择是名为
columns
(不要与另一个标准unix命令column
混淆)的gnu实用程序
使用如此大的宽度可以完全去除包裹:
columns --fill -W 10000 < file.txt
列--填充-W 10000
(部分内容。)谢谢你的回答,在这里发布之前,我做了“man-k wrap”,我完全错过了“fold”:(现在我们只需要
spindle
和mutate
@sdg:here's mutatate:pecho'hello world';sed-e's/\(.\)/\1\n/g';shuf;paste-s-d'
@sdg:因为spindle会在文档上戳洞:echo“hello world”sed's/\(.\)/\1/g'
或sed's/\(.\{40\})/\1/'docfile
或“sed's/(.\{8\})/\1\t/g docfile”或其他变体。fold还具有-s
选项,该选项在空格处断开。与fmt
或列相比,fold
只会添加新行以达到最大宽度(导致短线和长线的混合),而不是将文本整齐地填充到一定的宽度。
$ fmt -40 -t lorem
Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod
tempor incididunt ut labore et
dolore magna aliqua. Ut enim
ad minim veniam, quis nostrud
exercitation ullamco laboris
nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor
in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla
pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in
culpa qui officia deserunt mollit
anim id est laborum.
fmt -40 lorem | pr -To 6
columns --fill -W 10000 < file.txt