Linux sed:将字符串拆分为n个字符的行

Linux sed:将字符串拆分为n个字符的行,linux,sed,Linux,Sed,是否可以使用sed将字符串拆分为n个字符的行?例如,我有一个文件,其中数据写在一行中 Index:0070;Done:0;Fixed:1;Index:0056;Done:1;Fixed:1;Index:0070;Done:1;Fixed:0;... 如何将字符串分成行,每行26个字符?使用GNU时: sed -E 's/(.{26})/\1\n/g' file 输出: Index:0070;Done:0;Fixed:1; Index:0056;Done:1;Fixed:1; Index:00

是否可以使用sed将字符串拆分为n个字符的行?例如,我有一个文件,其中数据写在一行中

Index:0070;Done:0;Fixed:1;Index:0056;Done:1;Fixed:1;Index:0070;Done:1;Fixed:0;...
如何将字符串分成行,每行26个字符?

使用GNU时:

sed -E 's/(.{26})/\1\n/g' file
输出:

Index:0070;Done:0;Fixed:1; Index:0056;Done:1;Fixed:1; Index:0070;Done:1;Fixed:0; 使用GNU时:

sed -E 's/(.{26})/\1\n/g' file
输出:

Index:0070;Done:0;Fixed:1; Index:0056;Done:1;Fixed:1; Index:0070;Done:1;Fixed:0;
这可能适用于GNU sed:

sed 's/./&\n/26;P;D' file

这可能适用于GNU sed:

sed 's/./&\n/26;P;D' file

${str:pos:length}?。或者在每三个分号后面插入一个带有GNU sed的换行符:sed-E的/[^;]*;{3} /\1\n/g'文件非常感谢您的回复,赛勒斯${str:pos:length}?。或者在每三个分号后面插入一个带有GNU sed的换行符:sed-E的/[^;]*;{3} /\1\n/g'文件非常感谢您的回复,赛勒斯!不需要parens,只需在RHS中使用&1代替好主意即可。sed-E的/{26}/&\n/g'文件不需要paren,只需在RHS中使用&来代替好主意。sed-E的/{26}/&\n/g'文件