2番目の単語に2つのコレクションしかない行を抽出するためのGrepテンプレート

2番目の単語に2つのコレクションしかない行を抽出するためのGrepテンプレート

たとえば、コンテンツを含むファイルがあります。

hello world
it's nice to see you
amazing night
what a wonderful day
my name is Robert
still breathing
speaking bottom soul
something wrong

2番目の単語に正確に2つのコレクションがある行を一致させる必要があります。したがって、出力は次のようになります。

it's nice to see you
my name is Robert
speaking bottom soul

grepを使ってこれを行うにはどうすればよいですか?

ベストアンサー1

拡張正規表現を使用した grep:

grep -iE '^[^[:blank:]]+[[:blank:]]+([^aeiou]*[aeiou]){2}[^aeiou]*\>' file

grepとPCRE

grep -iP '^\S+\s+([^aeiou]*[aeiou]){2}[^aeiou]*\b' file

Perl(正直なところ、私はsteeldriverの意見とは別にこれを行いました)

perl -ane 'print if (lc($F[1]) =~ tr/aeiou/aeiou/) == 2' file

アッ

awk '{col2 = tolower($2); gsub(/[aeiou]/,"",col2)} length($2) - length(col2) == 2' file

おすすめ記事