tr
is all or nothing; it will replace all occurrences of the selected characters, regardless of context. For regex replacement, look at sed
- you even included this in your question's tags, but you don't seem to have explored how it might be useful?
sed 's/\(.\)\1/\1/g' test.txt
The dot matches any character; to restrict to only consonants, change it to [b-df-hj-np-tv-xz]
or whatever makes sense (maybe extend to include upper case; perhaps include accented characters?)
The regex dialect understood by sed
is more like the one understood by grep
without -E
(hence all the backslashes); though some sed
implementations also support this option to select the POSIX extended regular expression dialect.
Neither sed
not tr
need cat
to read standard input for them (though tr
obscurely does not accept a file name argument). See tangentially also Useless use of cat?