如何在文件中的固定数量的字符后插入换行符 [英] How to insert a new line character after a fixed number of characters in a file

查看:8
本文介绍了如何在文件中的固定数量的字符后插入换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个 bash 或 sed 脚本(最好是单行),我可以用它在大文本文件中的固定数量的字符后插入一个换行符.

I am looking for a bash or sed script (preferably a one-liner) with which I can insert a new line character after a fixed number of characters in huge text file.

推荐答案

这样的事情怎么样?改20是换行前的字符数,temp.text是要替换进去的文件.

How about something like this? Change 20 is the number of characters before the newline, and temp.text is the file to replace in..

sed -e "s/.{20}/&
/g" < temp.txt

这篇关于如何在文件中的固定数量的字符后插入换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆