I want to get unique chars within each line using regular expressions in a Shell Script (sh).
In other words, I want to remove any further occurrence of a char within each line.
I'm trying to answer this question: "What characters do appears in each line?"
For example, I'm trying to do something like this:
echo '1.Hi
2.This is
3.a huge file
4.with repeated chars
5.per
6.line' | sed 's/MYSTERIOUS_REGEX/MYSTERIOUS_REPLACE/g'
And the expected output is:
1.Hi
2.This
3.a hugefil
4.with repadcs
5.per
6.line
This is the explanation:
- Line 1: there isn't any repeated chars
- Line 2: '
i', 's' repeated - Line 3: '
', 'e' repeated - Line 4: '
e', 'a', 't', 'e', 'd', '', 'c', 'h', 'a', 'r' repeated - Line 5: there isn't any repeated chars
- Line 6: there isn't any repeated chars
OBS:
- If you achieve this using
shandsedyou obtain 5⭐s - If you achieve this using other tools (
bash,awketc), you obtain 3⭐s
̶D̶i̶s̶t̶r̶a̶c̶t̶o̶r̶ ̶ HINT:
The following regex matches lines which don't have repeated chars: ^(?:([A-Za-z])(?!.*\1))*$
echo "bleh" | grep -P '^(?:([A-Za-z])(?!.*\1))*$'
ble
echo "fooo" | grep -P '^(?:([A-Za-z])(?!.*\1))*$'
(empty)