title: How to find and replace the last space in each line of a file in BASH?
body: <p>I have a file like this:</p>
  
  <pre><code>Once upon a time there lived a cat.
  The cat lived in the forest.
  The forest had many trees.
  </code></pre>
  
  <p>I need to replace the last space per line with a "@", e.g.:</p>
  
  <pre><code>Once upon a time there lived a@cat.
  The cat lived in the@forest.
  The forest had many@trees.
  </code></pre>
  
  <p>I tried <code>sed 's/ .*$/@/g' file.txt</code>, but <code>.*</code> matches everything and deletes all of the text found there.</p>
  
  <p>How can I replace the last space per line with "@"?</p>