将字符串拆分为每行 n 个字符 [英] Split a string into lines of n characters each
本文介绍了将字符串拆分为每行 n 个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用 sed 将字符串拆分为每行 n 个字符?例如,我有一个文件,其中的数据是一行写入的.
Index:0070;Done:0;Fixed:1;Index:0056;Done:1;Fixed:1;Index:0070;Done:1;Fixed:0;...
如何将字符串分成多行,每行 26 个字符?
解决方案
使用 GNU sed:
sed -E 's/(.{26})/\1\n/g' 文件
输出:
<前>索引:0070;完成:0;固定:1;索引:0056;完成:1;固定:1;索引:0070;完成:1;固定:0;Is it possible to split the string to lines of n characters each with sed? For example, I have a file in which the data is written in one line.
Index:0070;Done:0;Fixed:1;Index:0056;Done:1;Fixed:1;Index:0070;Done:1;Fixed:0;...
How to break a string into lines, 26 characters each?
解决方案
With GNU sed:
sed -E 's/(.{26})/\1\n/g' file
Output:
Index:0070;Done:0;Fixed:1; Index:0056;Done:1;Fixed:1; Index:0070;Done:1;Fixed:0;
这篇关于将字符串拆分为每行 n 个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文