查找以一个特定字符开始并以另一个字符结尾的行 [英] Find lines starting with one specific character and ending with another one
本文介绍了查找以一个特定字符开始并以另一个字符结尾的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在以 a 开头的文件中找到一行,并且该行的最后一个词以 e 结尾。
I need to find a line in a file that starts with an a and the last word in the line ends with an e.
我该如何使用像 grep
这样的工具来做到这一点?
How can I do it with a tool like grep
?
推荐答案
Just say this:
/ code>
这意味着:从 ^
code> a ,然后是0或更多字符,最后是 e
( $ )。
This means: look for those lines starting (^
) with a
, then 0 or more characters and finally and e
at the end of the line ($
).
$ cat a
hello
and thisfinishes with e
foo
$ grep '^a.*e$' a
and thisfinishes with e
这篇关于查找以一个特定字符开始并以另一个字符结尾的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文