To replace all alphanumeric characters with X:
$ tr '[:alnum:]' 'X' <file
- XXXXX XXXXX
- XXXXX
To fill in the spaces between words:
$ tr '[:alnum:]' 'X' <file | sed 's/X X/XXX/g'
- XXXXXXXXXXX
- XXXXX
Or, using only sed:
$ sed 's/[[:alnum:]]/X/g; s/X X/XXX/g' file
- XXXXXXXXXXX
- XXXXX
Using sed as above, but also restrict the modification to lines that starts with a dash, preceded by optional spaces and/or tabs:
$ sed '/^[[:blank:]]*-/ { s/[[:alnum:]]/X/g; s/X X/XXX/g; }' file
- XXXXXXXXXXX
- XXXXX
You may notice that the filling in of spaces only works when there are no single letter words in the data. A string like This is a tree would be converted into XXXXXXXXX XXXX. To avoid this, you may do a simple loop:
sed -e '/^[[:blank:]]*-/ { s/[[:alnum:]]/X/g; :again' \
-e 's/X X/XXX/g; t again' -e '}' file
This performs the second substitution and then jump back to the again label if that substitution actually changed something.
Or, simpler, but would miss a trailing space character:
sed '/^[[:blank:]]*-/ { s/[[:alnum:]]/X/g; s/X /XX/g; }' file
Hello Worldis 10 non-whitespace characters. I would be fine with solutions that output either 10Xor 11X