It does not receive things in the original order, but this single-line awk works:
awk '{for(i=1;i<=length($0);i++){a[substr($0,i,1)]=1} for(i in a){printf("%s",i)} print "";delete a}' input.txt
Separate for easier reading, it can be standalone:
#!/usr/bin/awk -f {
Of course, the same concept can be implemented quite easily and in pure bash:
#!/usr/bin/env bash while read s; do declare -A a while [ -n "$s" ]; do a[${s:0:1}]=1 s=${s:1} done printf "%s" "${!a[@]}" echo "" unset a done < input.txt
Note that this is dependent on bash 4, due to the associative array. And it really does things in the original order, because bash does a better job of keeping the array keys in order than awk.
And I think that you have a solution using sed from Jose, although it has a bunch of additional pipe connections. :)
The last tool you talked about was grep . I'm sure you can't do this in traditional grep, but maybe some brave soul can build a perl-regexp (i.e. grep -P ) option using -o and backlinks. They need more coffee than me, though now.
ghoti
source share