Using awk with custom field separator:
First non-empty field:
awk -F ',+' '{print $2}' file VALUE1 VALUE3 VALUE6 VALUE8 Last non-empty field:
awk -F ',+' '{print $(NF-1)}' file VALUE2 VALUE5 VALUE7 VALUE8 Regex pattern ',+' will make 1 or more commas as a field separator.