Sam Trenholme's webpage
This article was posted to the Usenet group alt.hackers in 1995; any technical information is probably outdated.

News grepping


Article: 7835 of alt.hackers
From: fanf2@thor.cam.ac.uk (Tony Finch)
Newsgroups: alt.hackers
Subject: News grepping
Date: 18 May 1995 16:24:02 GMT
Organization: Trinity College, University of Cambridge
Lines: 30
Approved: Kibo (but is it ALLOWED?)
Message-ID: 3pfsb2$365@lyra.csx.cam.ac.uk
NNTP-Posting-Host: hammer.thor.cam.ac.uk
Status: RO

Can anyone point me towards a Unix tool that will reformat text into
one sentence per line?

ObHack:

newnews | fgrep From | awk -f reformat.awk $1 | sort | uniq -c +24 | sort -n -r

newnews prints the headers from unread articles

---- reformat.awk
{ name = ""; email = ""
  for(a = 2; a < 10; ++a)
    if($a ~ /@/) email = $a;
    else if(length($a)) name = name " " $a;

  flag = 1; while(flag) {
    if(name ~ /^ /) name = substr(name, 2, length(name)-1);
    else if(name ~ /^\(.*\)$/) name = substr(name, 2, length(name)-2);
    else if(name ~ /^".*"$/) name = substr(name, 2, length(name)-2);
    else flag = 0;
  }
  if(email ~ /^<.*>$/) email = substr(email, 2, length(email)-2);

  if(length(email)) printf("%-24s %s\n", name, email);
}
----

Tony.
--
No crap, less hat.



Back to index