title: Extracting minimum and maximum from line number grep
body: <p>Currently, I have a command in a bash script that greps for a given string in a text file and prints the line numbers only using sed ...</p>
  
  <pre><code>grep -n "&lt;string&gt;" file.txt | sed -n 's/^\([0-9]*\).*/\1/p'
  </code></pre>
  
  <p>The grep could find multiple matches, and thus, print multiple line numbers.  From this command's output, I would like to extract the minimum and maximum values, and assign those to respective bash variables.  How could I best modify my existing command or add new commands to accomplish this?  If using awk or sed will be necessary, I have a preference of using sed.  Thanks!</p>