I need to find a line in a file that starts with an <strong>a</strong> and the last word in the line ends with an <strong>e</strong>.
How can I do it with a tool like
Just say this:
grep '^a.*e$' file
This means: look for those lines starting (
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 eAnswer2:
Simple answer : use grep.
grep -E "^a.*e$" filename
^ indicates the beggining of the line
$ marks the end of the line
.* means any character (the
.) repeated from zero to any number of times (the
Many topics have already answered this questions, like <a href="https://stackoverflow.com/questions/4800214/grep-for-beginning-and-end-of-line" rel="nofollow">this one</a>.
If you want to know more of searching, you could look more in depth into <a href="https://www.gnu.org/software/findutils/manual/html_node/find_html/grep-regular-expression-syntax.html" rel="nofollow">REGEX</a>.