查找以一个特定字符开头并以另一个字符结尾的行

PFK*_*ang 2 unix grep pattern-matching

我需要找到与一个启动文件中的行一个,并在该行的最后一个字与结束ê.

我怎么能用像这样的工具grep呢?

fed*_*qui 11

只要这样说:

grep '^a.*e$' file
Run Code Online (Sandbox Code Playgroud)

这意味着:查找那些以(^)开头()a,然后是0或更多字符的行,最后是e在行的末尾($).

测试

$ cat a
hello
and thisfinishes with e
foo
$ grep '^a.*e$' a
and thisfinishes with e
Run Code Online (Sandbox Code Playgroud)