<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META content="MSHTML 5.00.2614.3500" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>This might help</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>{x[$0]++;}END{for (line in x) printf("%4d %s\n", 
x[line], line); }<BR></FONT></DIV>
<DIV><FONT face=Arial size=2>and the crude way to use it, as a file called 
awk.txt, is:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>awk -f awk.txt &lt;errorlog 
&gt;messagefile</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Any use?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Tom</DIV></FONT>
<BLOCKQUOTE 
style="BORDER-LEFT: #000000 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px">
  <DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV 
  style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> 
  <A href="mailto:david.halliday@gmail.com" title=david.halliday@gmail.com>David 
  Halliday</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>To:</B> <A 
  href="mailto:kent@mailman.lug.org.uk" title=kent@mailman.lug.org.uk>Kent Linux 
  User Group - General Topics</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>Sent:</B> Thursday, January 19, 2012 10:47 
  AM</DIV>
  <DIV style="FONT: 10pt arial"><B>Subject:</B> [Klug-general] sed - How to 
  delete all but first occurrence?</DIV>
  <DIV><BR></DIV>I have been playing with sed for a while. Some interesting 
  stuff,<BR>Here: <A 
  href="http://www.tutorialspoint.com/unix/unix-regular-expressions.htm">http://www.tutorialspoint.com/unix/unix-regular-expressions.htm</A><BR>And 
  here: <A 
  href="http://sed.sourceforge.net/sed1line.txt">http://sed.sourceforge.net/sed1line.txt</A><BR><BR>However 
  I am trying to remove from a log file (which is to be sent in an email) all 
  repeat occurrences of lines starting with "error:". So the log file looks like 
  this:<BR>====================================================================<BR><SPAN 
  style="FONT-FAMILY: courier new,monospace">some information: blable</SPAN><BR 
  style="FONT-FAMILY: courier new,monospace"><SPAN 
  style="FONT-FAMILY: courier new,monospace">This was happening: blah 
  blah</SPAN><BR style="FONT-FAMILY: courier new,monospace"><BR 
  style="FONT-FAMILY: courier new,monospace"><SPAN 
  style="FONT-FAMILY: courier new,monospace">error: something went 
  wrong</SPAN><BR style="FONT-FAMILY: courier new,monospace"><SPAN 
  style="FONT-FAMILY: courier new,monospace">error: I'm not happy</SPAN><BR 
  style="FONT-FAMILY: courier new,monospace"><SPAN 
  style="FONT-FAMILY: courier new,monospace">error: something went 
  wrong</SPAN><BR style="FONT-FAMILY: courier new,monospace"><SPAN 
  style="FONT-FAMILY: courier new,monospace">error: something went 
  wrong</SPAN><BR style="FONT-FAMILY: courier new,monospace"><SPAN 
  style="FONT-FAMILY: courier new,monospace">error: something went 
  wrong</SPAN><BR style="FONT-FAMILY: courier new,monospace"><SPAN 
  style="FONT-FAMILY: courier new,monospace">error: something went 
  wrong</SPAN><BR style="FONT-FAMILY: courier new,monospace"><SPAN 
  style="FONT-FAMILY: courier new,monospace">error: I'm not happy</SPAN><BR 
  style="FONT-FAMILY: courier new,monospace"><SPAN 
  style="FONT-FAMILY: courier new,monospace">error: I'm not happy</SPAN><BR 
  style="FONT-FAMILY: courier new,monospace"><BR>====================================================================<BR><BR>Now 
  I can use sed happily as:<BR><SPAN 
  style="FONT-FAMILY: courier new,monospace">sed -e 
  '/error:/d'</SPAN><BR><BR>This removes <B>all</B> error messages (In some 
  cases the script throws so many errors that to include them makes for a nasty 
  email) What I can't find is how to remove all but the first. I'm only 
  interested in the first error as in most cases all others will span from that. 
  Does anyone know how to do this? Or am I now using the wrong tool for the 
  job?<BR><BR>More Ideal would be to include only one instance of the unique 
  error messages but I believe that will be a little more complicated and more 
  time than it is worth (not to mention that a more complicated solution is 
  harder to explain to people I'm working with).<BR>
  <P>
  <HR>

  <P></P>_______________________________________________<BR>Kent mailing 
  list<BR>Kent@mailman.lug.org.uk<BR>https://mailman.lug.org.uk/mailman/listinfo/kent</BLOCKQUOTE></BODY></HTML>