grepがピリオドで終わる行だけを印刷しないのはなぜですか?

grepがピリオドで終わる行だけを印刷しないのはなぜですか?

ファイルがあります。

$cat File
A data file which contains a number of lines .
Most lines start with an upper case letter.
however some start with a lower case letter.
1 or 2 may start with a digit.

They should end with a full stop (period).
but not all do!
This line   has a combination of spaces and  tabs and ends with a space
3 lines are empty

You may want to verify the number of empty lines in this file.

There are some lines which only contain digits and white spaces, like the next 2.
1 2 3   4 5 6

いいえ、grepを使用して次に終わるすべての行を印刷したいと思います。.

$ grep '.$' File
A data file which contains a number of lines .
Most lines start with an upper case letter.
however some start with a lower case letter.
1 or 2 may start with a digit.
They should end with a full stop (period).
but not all do!
This line   has a combination of spaces and  tabs and ends with a space
3 lines are empty
You may want to verify the number of empty lines in this file.
There are some lines which only contain digits and white spaces, like the next 2.
1 2 3   4 5 6
7  8    9 0

問題はなぜこの行

but not all do!
This line   has a combination of spaces and  tabs and ends with a space
3 lines are empty

そして

1 2 3   4 5 6
7  8    9 0

.?で終わらなくても出力に追加されます。

ベストアンサー1

.「すべての文字」の正規表現です。したがって、任意の文字で終わる行を探していますが、当然、すべて空でない行です。

この地点を離れると大丈夫でしょう。

grep '\.$' File

おすすめ記事