Linux csplit command

Input file:

CLK00027   TESTDATA 0 S 600000 \r
0001RFC    192321 321321 321321 \r
0002 rfd  this is testdata1
CLK00027   TESTDATA 0 S 600000 \r
0001RFC    192321 321321 321321 \r
0002 rfd  this is testdata2

I Need to split this file into seperate files

file1.txt 

CLK00027   TESTDATA 0 S 600000 0001RFC    192321 321321 321321 0002 rfd  this is testdata1


file2.txt
CLK00027   TESTDATA 0 S 600000 0001RFC    192321 321321 321321 0002 rfd  this is testdata1

I am using a csplit command

csplit -b "%04d.$$.txt" $1 '/CLK0027/' {*}

this is working perfectly, however it splits the files and keeps the individual output files on seperate lines.

I need to (while the csplit is happening) write this out to a single line in the new separated files.

Not getting this to work.

a few things to note this file could be extremely large so whatever is used need to be able to handle very large amounts of characters in the file.

each CLK00027 is the start of a new file.

If I change my input to be on one line, then the csplit doesnt work and only writes out one file where I need an output file per "CLK0027" value.

I don't think that can be done with csplit . Try this little awk script instead:

awk -vPID=$$ '
NR == 1 ||
/CLK00027/      {if (FN) printf RS > FN
                 FN = sprintf ("xx%04d.%s.txt", CNT++, PID)
                }
                {printf "%s ", $0 > FN
                }
END             {printf RS > FN
                }
' file
cf xx000?*

---------- xx0000.1867.txt: ----------

CLK00027 TESTDATA 0 S 600000 \r 0001RFC 192321 321321 321321 \r 0002 rfd this is testdata1 

---------- xx0001.1867.txt: ----------

CLK00027 TESTDATA 0 S 600000 \r 0001RFC 192321 321321 321321 \r 0002 rfd this is testdata2