sed -e '
- Place a marker
\n at the beginning of the pattern ,which travels to the right during the process.
- We setup an infinite loop and provide for two exits inside the loop.
- One, if during the process the whole string ins emptied leaving only the marker, we exit knowing that this string comprised all duplicate stuff.
- Two, if during the process we find that the first element in the string is non-repeated. Implies, at least one non-duplicate located. Hence this line needs printing. We pull out the original which we had stored away in the hold area prior to beginning the process.
- The alternative is that the first element has at least a duplicate somewhere in the string which we go about in
t-loop totally purging that element's presence from the string.
Another way is using
Perl as shown:
perl -lne '
my $s = $_;
s/\Q$1\E//g while $s =~ /(.)(?=.*?\1)/g;
print $s if /./;
Here we make a copy of the line, and continuously look for duplicated elements and keep stripping away these from the original line. After the while loop ends, we print the copy provided something remains in the line (meaning, the non-duplicated stuff was left behind).