You can accomplish this task various ways, as shown below:
$ sed -e ':a s/,/\n/2;/\n/!b P;s/,.*\n/,/;ba ' file.csv
Explanation:
We try to change the second comma to a newline. If not possible => the pattern space had less than two and hence should be handed over to stdout.
OTW, we print the leading two comma-separated fields, then remove the second field such that the third now becomes the second nd so on.
$ perl -F, -lane ' my $f1 = shift @F; print join ",", $f1, $_ for @F; ' file.csv
Explanation:
Split each line into fields based on comma and perl
will store the fields in the array @F. The first field we shift off the array @F and store in the scalar $f1
. Then progressively print the elements of the array.
$ perl -F\(,\) -lane ' my $f1 = shift @F; print $f1, splice @F, 0, 2 while @F > 1 ; ' file.csv $ perl -F, -lane 'print $F[0], $_ for /,(?:(?!,).)*/g' file.csv $ sed -Ee 's/,?[^,]*/[&] /g' file.csv | dc -e " [q]sq [SMlN1+sNz1<a]sa [dnLMn10anlN1-dsN0<b]sb [?z0=q0sNlaxlbxclcx]sclcx "
Result:
1,a 1,b 1,c 2,b 2,c 3,e 3,f 4,l
4,1
(four-one) be4,l
(four-ell) like in the input file?