How to insert a new line character after a fixed number of characters in a file

前端 未结 7 545
别那么骄傲
别那么骄傲 2020-12-02 12:16

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.

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-02 13:09

    Let N be a shell variable representing the count of characters after which you want a newline. If you want to continue the count accross lines:

    perl -0xff -pe 's/(.{'$N'})/$1\n/sg' input
    

    If you want to restart the count for each line, omit the -0xff argument.

提交回复
热议问题