In the third line you just remove columns 2-4 with spaces in it, not extracting any data. And you have different "Granysmithes" in your input and output files. Anyway you can try:
sed -r 's/, +,/,/; s/, +,/,/' INPUTFILE
or (for 2-5 fields):
sed -r 's/, +,/,/; s/, +,/,/; s/, +,/,/' INPUTFILE
Hi yazu. thanks I'll give that a try. The capital letter was a mistake, sorry.
Is there a way of doing it for an arbitrary number of fields, I actually need it in the range 2 to 102 but because I do not understand your sed command I cannot adapt it. Could you please elaborate on it.
---------- Post updated at 02:14 PM ---------- Previous update was at 01:17 PM ----------
I tried to wrap my head around it for a while now but I don't understand it at all any further help greatly appreciated.
Well, I took your advice and tried something different (and messy), an awk script. so, for example to remove blanks between 2 and 105 i would type
./script.awk Inputfile.csv 2 105
It works but at the end of the output I want it also spits out
awk: cannot open 2 (No such file or directory)
why is it trying to open it as a file? I just want it as an argument/parameter to the script, is there a way to avoid this? The script is below
#!/usr/bin/awk -f
BEGIN { FS = ","}
FNR>1 {for (i = 1; i < ARGV[2]; i++) printf $i",";
for (i = ARGV[2]; i <= ARGV[3] ; i++) if ($i!="") printf $i",";
for (i = ARGV[3]+1; i <= NF; i++) printf $i","; print ""}