I have an address file that is like below
$ cat hier.dat
/City-A/Streetx/House1,100
/City-B/Streety/House2,200
$
I need to generate more lines by expanding the hierarchy from the beginning. The required output is
/City-A,100
/City-A/Streetx,100
/City-A/Streetx/House1,100
/City-B,200
/City-B/Streety,200
/City-B/Streety/House2,200
The below perl command looks logically correct but it is not giving the correct results
$ perl -F, -lane ' $s=""; while($F[0]=~/\G\/.+?\//g) {$s.=$&; print $s.",".$F[1] } ' hier.dat
/City-A/,100
/City-B/,200
Any other shell solution is also welcome!