我有一个文件
$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