
Das Problem besteht darin, ein Skript zu schreiben, das eine Datei als Argument verwendet und alle Zeilen ausgibt, die -mindestens- alle Vokale enthalten, -unabhängig von der Reihenfolge-, aber mit [keine zwei gleichen aufeinanderfolgenden Vokale].
zB ist aeaiou erlaubt, aber nicht aaeiou wegen des 'aa'
Das folgende Skript ist fast alles, was ich brauche, aber es prüft nicht die Konsekutivität.
egrep -i '.[a]+' ${1} | egrep -i '[e]+' | egrep -i '[i]+' | egrep -i '[o]+'| egrep -i '[u]+'
Hinweis: Ich darf Grep- und Schleifenkonstrukte verwenden, aber keine obskuren/hochrangigen Befehle.
gelöst;
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]+'
Antwort1
Sofern Sie die gesamte Zeile ausschließen möchten, wenn sie doppelte Vokale enthält, sollte dies funktionieren:
grep -i a file | \
grep -i e | \
grep -i i | \
grep -i o | \
grep -i u | \
grep -v -i '\([aeiou]\)\1'
Antwort2
Anstatt grep
mehrere Male aufzurufen, können Sie auch einen einzigen Aufruf von verwenden sed
, entweder
sed -rn '/(aa|ee|ii|oo|uu)/d; /a/{/e/{/i/{/o/{/u/p}}}}'
oder
sed -rn '/([aeiou])\1/d; /a/{/e/{/i/{/o/{/u/p}}}}'
wenn Sie lieber Rückverweise verwenden möchten.
Antwort3
Verwenden Sie Ihre Frage (leicht modifiziert, mit einem Zeilenumbruch vor dem but not aaeiou because of the 'aa'
) als Eingabe:
$ 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,
Das awk
Skript aktiviert den Groß-/Kleinschreibungs-unabhängigen Modus, entfernt Zeilen mit Doppelvokalen und druckt dann Zeilen, die mindestens einen Vokal von jedem Wort enthalten.