awk novice here, was wondering if this is doable.
My file:
CCDDBBAA
EFGHAC
KJLDFU
ABBAAC
Desired output:
ABCD
ACEFGH
DFJKLU
ABC
I want to sort the strings in my file alphabetically and remove the duplicates within the string.
Thanks!
This might work for you (GNU sed & sort):
sed 's/\s*/\n/g;s/.*/echo "&"|sort -u/e;s/\n//g' file
Remove white space and separate each character by a newline. Sort the lines generated removing duplicates. Remove the introduced newlines.
With gawk:
awk -v FS="" '{
for(i=1;i<=NF;i++){
if ($i in a == 0){
a[$i]
}
};
d=asorti(a,b);
for(x=1;x<=d;x++){
printf "%s",b[x]
};
print "";
delete a;
delete b
}'