awk -F, '
# if NF not equal to 7
NF != 7 {
# If ORS not equal to " " set ORS = " " else set ORS = RS (newline by default)
ORS = ( ORS != " " ? " " : RS )
}
{
# This stmt rebuilds current record, this is to set OFS = |
$1 = $1
}
# 1 == true. If true, default awk operation is to print current record
1
' OFS=\| file
The solution you get here can only be as good as your description of the problem.
You say you actual CSV file has 21 columns (fields?) you the sample data you supply only has 4 line of 7 fields.
Yoda states his solution is based on the sample data, probably due to this confusion.
RavinderSingh13's solution will only work if your CSV files always starts with the digit "1" and/or contains the string "ABC".
If these are working for you all is good but if you need something that works for your actual data you might need to provide a better description of what is needed.
For example:
how many fields are in the actual data
are records split over more than 2 lines
do you always need a space inserted when lines are joined (like what happens when lines 2 and 3 are joined from you sample data)