社内se × プログラマ × ビッグデータ

プログラミングなどITに興味があります。

重複 typo を正規表現の後方参照でチェック

以下のように、不要な重複が含まれるテキスト (typo.txt) があるとする。

A typo is a mistake made in the typing process.
A typo typo is a mistake made in the typing process.
A typo is a a mistake made in the typing process.
A typo is a mistake made in in the typing process.

このテキストに対して、以下のコマンドを使えば重複部分をピックアップすることができる。
※ただし、同じ行内で重複している場合のみ

$ egrep -i '\<([a-z]+) +\1\>' typo.txt

A typo typo is a mistake made in the typing process.
A typo is a a mistake made in the typing process.
A typo is a mistake made in in the typing process.