使用 sed 命令将双辅音字母替换为一个

Replace double consonant letters with one using sed command

如何使用 sed Linux 命令用一个字母替换双辅音。示例:WILLIAM -> WILIAM。 grep -E '(.)+' 命令查找连续出现两个相同辅音的单词,但如何将它们替换为仅出现一次的字母?

我试过了

cat test.txt | head | tr -s '[^AEUIO\n]' '?'

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/\(.\)//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?

匹配一个辅音,记住它在\( \),然后再匹配</code>并用它代替自己。 </p> <pre><code>sed 's/\([bcdfghjklmnpqrstvxzBCDFGHJKLMNPQRSTVXZ]\)//'