home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / relay / anews / b.to.a < prev    next >
Text File  |  1986-10-29  |  798b  |  36 lines

  1. #! /bin/sh
  2. # bnewstoa: B-format news to A-format converter (why, oh, why?) (thanks, Norman)
  3. PATH=/bin:/usr/bin:/usr/ucb; export PATH
  4.  
  5. awk '
  6. NR==1,/^$/    {        # headers: save A headers only
  7.     if ($0 ~ /^Message-ID: /)
  8.         msgid=$2
  9.     else if ($0 ~ /^Newsgroups: /)
  10.         ngs=$2
  11.     else if ($0 ~ /^Path: /)
  12.         path=$2
  13.     else if ($0 ~ /^Date: /) {
  14.         date = $2    # skip "Date:"
  15.         for (i = 3; i <= NF; i++)
  16.             date = date " " $i    # append remaining fields
  17.     } else if ($0 ~ /^Subject: /)
  18.         subj=$2
  19.     else if ($0 ~ /^$/) {    # end of headers: spew out A-format equivalent
  20.         print "A" msgid
  21.         print ngs
  22.         print path
  23.         print date
  24.         print subj
  25.         inbody = "yes"
  26.         noblanksyet = "yes"
  27.     }
  28. }
  29. inbody=="yes"    {    # copy body except first blank line, if present
  30.     if ($0 ~ /^$/ && noblanksyet == "yes")
  31.         noblanksyet = "no"
  32.     else
  33.         print
  34. }
  35. '
  36.