I found a one-line sed command on this site which removes duplicate entries in $PATH. There is one concept that I can't get my mind around.It uses saved matches in the match section to detect the duplicate, and then replaces the match with \1\2. In the example below, I can't understand why \1 is not always 1111.The test case obviously shows that the \1 match progresses further down the pattern space, but I can't understand why.sed script (sed_cmd):p  #debug:bs/[:;]\([^:;]*\)\([:;].*\)[;:]\1/;y\1yx\2x/ps/[yx]//g   #debug remove the field indicators for the next passs/;/:/g     #debugtbs/^\([^:]*\)\(:.*\):\1/\1\2FixedFirst/aDoneTest command + output:echo 0000:1111:2222:3333:4444:1111:2222:3333:0000 | sed -f sed_cmd0000:1111:2222:3333:4444:1111:2222:3333:00000000;y1111yx:2222:3333:4444x:2222:3333:00000000:1111;y2222yx:3333:4444x:3333:00000000:1111:2222;y3333yx:4444x:00000000:1111:2222:3333:4444FixedFirstDone
How do back-references match in sed?
sed;regular expression