title: remove some lines in log file
body: <p>I have a big log file.</p>
  
  <p>After removing the timestamp of each line, I sort it by <code>cat logfile | sort -u &gt; logfile</code>, so that the logs are clean and organized as</p>
  
  <pre><code>failed to correct PL.ASBF..HHZ.2011.348 because of divided by zero
  failed to correct PL.ASBF..HHZ.2011.349 because of divided by zero
  failed to correct PL.ASBF..HHZ.2011.350 because of divided by zero
  .
  . (lines not shown here)
  .
  failed to correct PL.ASBF..HHZ.2015.364 because of divided by zero
  failed to correct PL.ASBF..HHZ.2015.365 because of divided by zero
  .
  .
  . (lines not shown here)
  .
  .
  failed to correct PL.HSPB..HHZ.2011.128 because of Illegal format
  failed to correct PL.HSPB..HHZ.2011.129 because of Illegal format
  failed to correct PL.HSPB..HHZ.2011.130 because of Illegal format
  .
  . (lines not shown here)
  .
  failed to correct PL.HSPB..HHZ.2014.364 because of Illegal format
  failed to correct PL.HSPB..HHZ.2014.365 because of Illegal format
  </code></pre>
  
  <p>I can get the logged items (e.g. <code>PL.HSPB</code> in above example) by </p>
  
  <pre><code>grep -oE " [0-9A-Z]*\.[0-9A-Z]*" logfile | sort -u
  </code></pre>
  
  <p>However, I also want to known the date info and to make it clearer, I want to remove the intermedia lines. For example, </p>
  
  <pre><code>failed to correct PL.HSPB..HHZ.2011.128 because of Illegal format
  failed to correct PL.HSPB..HHZ.2011.129 because of Illegal format
  failed to correct PL.HSPB..HHZ.2011.130 because of Illegal format
  .
  . (lines not shown here)
  .
  failed to correct PL.HSPB..HHZ.2014.364 because of Illegal format
  failed to correct PL.HSPB..HHZ.2014.365 because of Illegal format
  </code></pre>
  
  <p>after removal becomes</p>
  
  <pre><code>failed to correct PL.HSPB..HHZ.2011.128 because of Illegal format
  failed to correct PL.HSPB..HHZ.2014.365 because of Illegal format
  </code></pre>
  
  <p>i.e., for an item, only the first and last lines are kept (the digits are year and julian day).</p>
  
  <p>Is there any shell command to make this with easy?</p>