问题是编写一个脚本,该脚本接受一个文件作为参数,并打印包含 - 至少 - 所有元音的所有行, - 无论顺序如何 - 但带有 [没有两个相同的连续元音]。
例如 aeaiou 是允许的,但不允许 aaeiou 因为 'aa'
下面的脚本几乎是我所需要的,但它不检查连续性。
egrep -i '.[a]+' ${1} | egrep -i '[e]+' | egrep -i '[i]+' | egrep -i '[o]+'| egrep -i '[u]+'
注意:我可以使用 grep 和循环结构,但不能使用模糊/高级命令。
解决了;
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
您也可以使用一次调用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
脚本启用不区分大小写的模式,删除包含双元音的行,然后打印包含每个元音至少一个的行。