想象一下,你的脚本会输出一些真正奇怪的输出,如:
fdjsagnfafeowkagfdsngodagfoeagnfiosnthoaogjerapogrjeagnfdosngtnsrhig ofskhnIAGNRIEAGPREAOGJRIAEGRNIEOASGNFAIGRNESUIGRIOAEGRNIAENGRUEAOREANFDOIGNRUESIGORNAEIGNREIOAGRIUESGRJOEAGRNEOSIGRNEPAGRJAEIO
我知道废话。可能这样看起来会更好:
fdjsagnfafeowkagfdsngodagfoeagnfiosnthoaogjera
pogrjeagnfdosngtnsrhig ofskhnIAGNRIEAGPREAOGJR
IAEGRNIEOASGNFAIGRNESUIGRIOAEGRNIAENGRUEAOREAN
FDOIGNRUESIGORNAEIGNREIOAGRIUESGRJOEAGRNEOSIGR
NEPAGRJAEIO
我试图用bash中的base64编码字符串数据来做这件事。我怎么能这样做?
答案 0 :(得分:3)
对于您的示例输入,fold
将生成您请求的输出。假设我们有这个文件:
$ cat longline
fdjsagnfafeowkagfdsngodagfoeagnfiosnthoaogjerapogrjeagnfdosngtnsrhig ofskhnIAGNRIEAGPREAOGJRIAEGRNIEOASGNFAIGRNESUIGRIOAEGRNIAENGRUEAOREANFDOIGNRUESIGORNAEIGNREIOAGRIUESGRJOEAGRNEOSIGRNEPAGRJAEIO
制作宽度为46个字符的行:
$ fold -w 46 longline
fdjsagnfafeowkagfdsngodagfoeagnfiosnthoaogjera
pogrjeagnfdosngtnsrhig ofskhnIAGNRIEAGPREAOGJR
IAEGRNIEOASGNFAIGRNESUIGRIOAEGRNIAENGRUEAOREAN
FDOIGNRUESIGORNAEIGNREIOAGRIUESGRJOEAGRNEOSIGR
NEPAGRJAEIO
如果要在管道中使用它,fold
也接受stdin:
$ fold -w 46 <longline
fdjsagnfafeowkagfdsngodagfoeagnfiosnthoaogjera
pogrjeagnfdosngtnsrhig ofskhnIAGNRIEAGPREAOGJR
IAEGRNIEOASGNFAIGRNESUIGRIOAEGRNIAENGRUEAOREAN
FDOIGNRUESIGORNAEIGNREIOAGRIUESGRJOEAGRNEOSIGR
NEPAGRJAEIO
在Linux上,fold
是GNU coreutils的一部分,默认情况下应该安装。它也可以在Mac OSX下找到。