title: How to remove lines from a list which can be found within other longer lines in the list?
body: <p>I have a file, <code>list.txt</code>, like this:</p>
  
  <pre><code>cat
  bear
  tree
  catfish
  fish
  bear
  </code></pre>
  
  <p>I need to delete any lines which are already fully found somewhere else in the document, either as a duplicate line, or found within another longer line. For e.g., the lines "bear" and "bear" are the same, so one of these is deleted; "cat" can be found completely within "catfish", so "cat" is deleted. The output would look like this:</p>
  
  <pre><code>catfish
  tree
  bear
  </code></pre>
  
  <p>How can I delete all duplicate lines including the lines which are found within longer lines in a list?</p>
  
  <p>So far, I have this:</p>
  
  <pre><code>#!/bin/bash
  touch list.tmp
  while read -r line
  do
      found="$(grep -c $line list.tmp)"
      if [ "$found" -eq "1" ]
      then
          echo $line &gt;&gt; list.tmp
          echo $line" added"
      else
          echo "Not added."
  fi
  done &lt; list.txt
  </code></pre>