$ sed -n -f script.sed file
file is a file containing the example pathname that you mentioned.
This script implements a double loop that processes each line of input. It expects to get lines with pathnames only.
The outer loop (labelled
outer) copies the current line to the hold space (
h). The inner loop (labelled
inner), which is completely skipped if the line is empty, then prints the current line if it's not empty. Then the last
/<anything> is removed from the current line, and, if that substitution modified the data,
t inner loops back to the start of the inner loop.
Otherwise, the saved line is fetched from the hold space (
g) and the first
/<anything> is removed from it. If that substitution modified the data, the code loops back to the start of the outer loop.
The net result is that you get your complete pathname printed, then you get each pathname that is generated by chopping off successive path components from the end of it.
Then the same thing is repeated with the pathname that you get by removing the first path element from the original pathname. Etc.
If you swap the two substitutions in the code, you get the same thing, but in another order: