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


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 grep?


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 ($).

<h3>Test</h3> $ cat a hello and thisfinishes with e foo $ grep '^a.*e$' a and thisfinishes with e


Simple answer : use grep.

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

the ^ indicates the beggining of the line the $ marks the end of the line the .* 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>.


  • How to restrict number of concurrent processes?
  • Selenium and Google - How do you use cookies?
  • Use neo4j server instead of embedded mode
  • c++ search a vector for element first seen position
  • custom string delimiters stringtemplate-4
  • Is there any purpose for h2-h6 headings in HTML5?
  • php is_file always return false
  • Validate jQuery plugin, field not required
  • How to make JSON.NET deserialize to Microsoft Date Time?
  • How to remove a SwiftyJSON element?
  • iOS: Detect app start via notification press
  • Admob requires api-13 or later can I not deploy on old API-8 phones?
  • Python CGI os.system causing malformed header
  • Ajax Loaded meta Tags
  • formatting the colorbar ticklabels with SymLogNorm normalization in matplotlib
  • R - Combining Columns to String Based on Logical Match
  • Exchange data b/w iOS devices using Bluetooth 4.0
  • Master page gives error
  • Uncaught Error: Could not find module `ember-load-initializers`
  • Read text file and split every line in MSBuild
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • How to set/get protobuf's extension field in Go?
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Sending data from AppleScript to FileMaker records
  • Running a C# exe file
  • Knitr HTML Loop - Some HTML output, some R output
  • JSON with duplicate key names losing information when parsed
  • Symfony2: How to get request parameter
  • When should I choose bucket sort over other sorting algorithms?
  • How do you troubleshoot character encoding problems?
  • Jquery - Jquery Wysiwyg return html as a string
  • Google cloud sdk not working when python points python3
  • Why winpcap requires both .lib and .dll to run?
  • Return words with double consecutive letters
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • how to add data labels for bar graph in matlab
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Understanding cpu registers
  • coudnt use logback because of log4j