Search code examples
newlinekshline-breaks

Add a line break every fix number of byte


I am using AIX and ksh.

I have a very large file which does not have line break. I am sure that the file is generated from fixed record length file.

For example, if the file size is 123456789000, the file should contain 123456789 records, each 1000 byte.

Because missing line break char, i.e. LF, it is very difficult to handle this file.

I have tried the dd command using bs=1000. But, seems that cannot add a \n after every block.

Using split command can break the file into 123456789 files, each 1000 byte size. This is quite a trouble then to continue.

Is there any way to add a \n every 1000 byte ?

If I can add back \n every 1000 byte, there will be more easy for me to handle the file.

BTW, prefer to use ksh script, no python, no perl. no C compiler.

Thanks in advance.


Solution

  • You can use

    fold -w 1000 inputfile > outputfile