
問題は、ファイルを引数として受け取り、少なくともすべての母音を含むすべての行を、順序に関係なく印刷するスクリプトを作成することですが、[同じ母音が連続しない]。
例えば、aeaiou は許可されますが、'aa' があるため aaeiou は許可されません。
以下のスクリプトはほぼ必要なものですが、連続性をチェックしません。
egrep -i '.[a]+' ${1} | egrep -i '[e]+' | egrep -i '[i]+' | egrep -i '[o]+'| egrep -i '[u]+'
注: grep とループ構造は使用できますが、obscur/高レベルのコマンドは使用できません。
解決しました。
egrep -vi '[a][a]' ${1} | egrep -vi '[e][e]' | egrep -vi '[i][i]' | egrep -vi '[o][o]' | egrep -vi '[i][i]' | egrep -i '[a]+' | egrep -i '[e]+' | egrep -i '[i]+' | egrep -i '[o]+'| egrep -i '[u]+'
答え1
二重母音がある場合に行全体を除外したい場合、次のようにすればうまくいくはずです。
grep -i a file | \
grep -i e | \
grep -i i | \
grep -i o | \
grep -i u | \
grep -v -i '\([aeiou]\)\1'
答え2
を複数回呼び出す代わりにgrep
、 を 1 回だけ呼び出すこともできますsed
。
sed -rn '/(aa|ee|ii|oo|uu)/d; /a/{/e/{/i/{/o/{/u/p}}}}'
または
sed -rn '/([aeiou])\1/d; /a/{/e/{/i/{/o/{/u/p}}}}'
後方参照を使用する場合。
答え3
質問(少し変更し、 の前に改行を入れたものbut not aaeiou because of the 'aa'
)を入力として使用します。
$ cat hehe.txt
The problem is to write a script that takes a file as argument
and prints all the lines that contain -at least- all the vowels ,
-regardless of ordering-, but with [no two same consecutive vowels].
e.g aeaiou is allowed,
but not aaeiou because of the 'aa'
The script below is almost what I need, but it does not check for
consecutiveness.
$ awk 'BEGIN { IGNORECASE=1 };
! /aa|ee|ii|oo|uu/ && ( /a/ && /e/ && /i/ && /o/ && /u/ )' hehe.txt
The problem is to write a script that takes a file as argument
-regardless of ordering-, but with [no two same consecutive vowels].
e.g aeaiou is allowed,
このawk
スクリプトは、大文字と小文字を区別しないモードを有効にし、二重母音を含む行を削除してから、各母音を少なくとも 1 つ含む行を出力します。