You can obtain the desired output with the following awk snippet:
awk -F, '{ if (f == $1) { for (c=0; c <length($1) + length(FS); c++) printf " "; print $2 FS $3 } else { print $0 } } { f = $1 }' FILE
Or just the awk program formatted:
{
if (f == $1) {
for (c=0; c < length($1) + length(FS); c++)
printf " "
print $2 FS $3
} else {
print $0
}
}
{
f = $1
}
Explanation:
If the first field ($1) matches the first field of the previous line (f, which is assigned at the end of processing each line with f = $1), then we print spaces for the length of the field to be omitted plus the length of the field separator (FS). Else, we just print the entire line ($0).
If the comma needs to be kept, the awk program should be this:
{
if (f == $1) {
for (c=0; c < length($1); c++)
printf " "
print FS $2 FS $3
} else {
print $0
}
}
{
f = $1
}
This will print:
a,123,xyz
,345,zyx
b,123,xyz
,345,zyx