
下線で区切られた複数の部分文字列で構成される文字列があります。たとえば: AbcdAEfd_hEgdgE_AbAAAAA
。各部分文字列から最初のコレクションを除くすべてのコレクションを削除する必要があります。だから:
AbcdAEfd
->Abcdfd
hEgdgE
->hEgdg
AbAAAAA
->Ab
結果の文字列は次のようになります。Abcdfd_hEgdg_Ab
答え1
パラメータ置換のみを使用する純粋なbashソリューション:
#! /bin/bash
suffix=${1#*[aeiou]}
prefix=${1%$suffix}
vowel=${prefix: -1}
prefix=${prefix%?} # Remove the vowel from the prefix
suffix=${suffix//[aeiou]/} # Remove the vowels.
echo "$1 -> $prefix$vowel$suffix."
答え2
使用perl
できる幅0のフッシュ正規表現構文。
perl -pe "s/(?<=[aeiou])([^aeiou_]*)[aeiou]([^aeiou_]*)/\1\2/ig"
次のコードスニペットは、入力行を複数の部分文字列ではなく単一の文字列として扱います。
perl -pe "s/(?<=[aeiou])([^aeiou]*)[aeiou]/\1/ig"
答え3
Pythonは重要ですか?これは働きます:
cat anonymous.txt | python -c "import sys; x=sys.stdin.read(); print(x[0]+''.join([z for z in x[1:] if z not in 'AEIOUaeiou']))"
私もいくつかの失敗でティーパイプと名前付きパイプを試してみました。
makefifo pipe; cat anonymous.txt | tee >(cut -b1 >> pipe&) >(cut -b1- | tr -d aeiouAEIOU >> pipe&) > /dev/null; cat pipe | xargs -d '\n'
答え4
これはあなたに役立ちます(GNU sed):
sed 's/^/\n/;ta;:a;s/\n$//;t;s/\n\([^aeiou_]*[aeiou]\)/\1\n/i;:b;s/\n\([^aeiou_]*\)[aeiou]/\1\n/i;tb;s/\n\([^aeiou]*\)/\1\n/i;ta' file