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

관련 정보