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
即使它們不以
.
?結尾,也添加到輸出中
.
是“任何字元”的正則表達式。因此,您正在尋找以任何字元結尾的行,這並不奇怪所有非空行。逃脫點,你應該沒問題:
grep '\.$' File