This is somewhat ugly, as my C skills are rusty, but it works pretty well...
Save as redelimit.c
and compile it like this:
gcc -o redelimit redelimit.c
or
cc -o redelimit redelimit.c
and then run like this
./redelimit
If you want to save the output, do this:
./redelimit > newfile.csv
It expects the input file to be called input.csv
#include <stdio.h>
#include <string.h>
FILE *fp;
int main()
{
int i,n;
int inquotes;
char line[1024];
fp = fopen ("input.csv", "r");
/* Loop through all lines in file */
while(fgets(line, sizeof(line), fp) != NULL)
{
/* Remember if we are inside double quotes so we know what to do with spaces */
inquotes=0;
/* Parse each character in line */
int len = strlen(line);
for(i=0;i<len;i++){
/* If these are double quotes, toggle value of "inquotes" variable */
if(line[i]=='"'){
inquotes=1-inquotes;
continue;
}
if(line[i]==' '){
if(inquotes){putchar(' ');} else {putchar(',');}
continue;
}
putchar(line[i]);
}
}
fclose(fp);
}
Output
abcd,Bala Chuppala,1,200,,Norway,,?,?,9,88
ab,Joh Tanni S V S,200,2,?,Swiss,1,100,200,?,