Combining rows in a text file with a character limit

I have a file that contains several thousands rows. Here is an example.

^411912$
^487267$
^643776$
^682249$
^687737$
^692328$
^693767$
^695483$
^697289$
^757411$
^776688$
^778953$
^806123$
^872262$
^877877$
^839837$
^76666$
^72018$
^23330$
^73250$
^59769$
^55325$
^728647$
^28444$
^21824$

I want to run a script that will create a new file with each row combined, seperated by a "|", and with a character limit per row of 1024 characters.

Try:

cat file | tr '\n' ' ' | fold -sc1024 | sed 's/ $//;s/ /|/g'

Thank you very much! That worked great. I had never thought of using fold. Again thank you.

awk '{X=(X=="")?$0:X OFS $0; if (length(X)>30) {print X;X=""}}
   END{if (X!="") print X}' OFS="|" infile