That is an extremely complicated pipeline that doesn't seem to be accomplishing a lot of what you want to do. The output you say you want also removes some spaces and hyphens that don't fit with your stated desire to change spaces to commas when used as field separators between the first three fields.
The following trims the 2nd line of the input to the length of the modified 1st line. (Assuming that there will typically be more than three lines of input in the files you process, you can't adjust the 2nd line of the file to match the longest output line that will be produced unless you store the entire output in memory before printing it, or reading the input file twice.)
awk '
NR == 2 {
printf("%*.*s\n", w - 1, w - 1, $0)
next
}
{ for(i = 1; i <= NF; i++) {
printf("%s%s", $i, (i < 3) ? "," : (i == NF) ? ORS : OFS)
w += length($i) + 1
}
}' SIM_Sale.csv
With your sample input, this produces the output:
FName,LName,Date & time
-----------------------
Gilles,John,14/12/17 12:30:45
If you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk .
P.S. I had a cut-and-paste error omitting the 1st line of the awk script (as noted by Scrutinizer in post #3). That missing line has now been added above.
Sure you want Anicet Williams split into two fields? As long as field separators (here: spaces) can occur within field values, there's no reliable way to tell one from the other.