Find lines starting with one specific character and ending with another one Find lines starting with one specific character and ending with another one unix unix

Find lines starting with one specific character and ending with another one


Just say this:

grep '^a.*e$' file

This means: look for those lines starting (^) with a, then 0 or more characters and finally and e at the end of the line ($).

Test

$ cat ahelloand thisfinishes with efoo$ grep '^a.*e$' aand thisfinishes with e


Simple answer : use grep.

grep -E "^a.*e$" filename

the ^ indicates the beggining of the linethe $ marks the end of the linethe .* means any character (the .) repeated from zero to any number of times (the *).Many topics have already answered this questions, like this one.If you want to know more of searching, you could look more in depth into REGEX.