2015-04-21 67 views
1

想象一下你的腳本輸出像一些真正奇怪的輸出:總結新線過長的字符串輸出在bash

fdjsagnfafeowkagfdsngodagfoeagnfiosnthoaogjerapogrjeagnfdosngtnsrhig ofskhnIAGNRIEAGPREAOGJRIAEGRNIEOASGNFAIGRNESUIGRIOAEGRNIAENGRUEAOREANFDOIGNRUESIGORNAEIGNREIOAGRIUESGRJOEAGRNEOSIGRNEPAGRJAEIO 

廢話,我知道。也許這樣看起來會更好:

fdjsagnfafeowkagfdsngodagfoeagnfiosnthoaogjera 
pogrjeagnfdosngtnsrhig ofskhnIAGNRIEAGPREAOGJR 
IAEGRNIEOASGNFAIGRNESUIGRIOAEGRNIAENGRUEAOREAN 
FDOIGNRUESIGORNAEIGNREIOAGRIUESGRJOEAGRNEOSIGR 
NEPAGRJAEIO 

我想在bash中用base64編碼的字符串數據做到這一點。我怎麼能這樣做?

+0

閱讀此:http://stackoverflow.com/a/20065991/797495 –

+0

你應該能夠存儲輸出作爲變量,然後嘗試像這樣:'echo $ varname | base64' – ryekayo

+0

我沒有使用java,也沒有包裝解析輸出。我正在包裝它,因爲如果我沒有,它會迷路。數據通過網絡發送,而且非常複雜。 –

回答

3

對於您的示例輸入,fold將生成您請求的輸出。假設我們有這樣的文件:

$ cat longline 
fdjsagnfafeowkagfdsngodagfoeagnfiosnthoaogjerapogrjeagnfdosngtnsrhig ofskhnIAGNRIEAGPREAOGJRIAEGRNIEOASGNFAIGRNESUIGRIOAEGRNIAENGRUEAOREANFDOIGNRUESIGORNAEIGNREIOAGRIUESGRJOEAGRNEOSIGRNEPAGRJAEIO 

爲了與寬度46個字符的行:

$ fold -w 46 longline 
fdjsagnfafeowkagfdsngodagfoeagnfiosnthoaogjera 
pogrjeagnfdosngtnsrhig ofskhnIAGNRIEAGPREAOGJR 
IAEGRNIEOASGNFAIGRNESUIGRIOAEGRNIAENGRUEAOREAN 
FDOIGNRUESIGORNAEIGNREIOAGRIUESGRJOEAGRNEOSIGR 
NEPAGRJAEIO 

如果你想在一個管道中使用它,fold也接受標準輸入:

$ fold -w 46 <longline 
fdjsagnfafeowkagfdsngodagfoeagnfiosnthoaogjera 
pogrjeagnfdosngtnsrhig ofskhnIAGNRIEAGPREAOGJR 
IAEGRNIEOASGNFAIGRNESUIGRIOAEGRNIAENGRUEAOREAN 
FDOIGNRUESIGORNAEIGNREIOAGRIUESGRJOEAGRNEOSIGR 
NEPAGRJAEIO 

在Linux上,foldGNU coreutils的一部分,應默認安裝。它也可在Mac OSX下獲得。