#!/bin/bash # Working: 2001-Jan-22 # revision: 2002-May-02 # The purpose is to take chat logs generated from curfloo # ( http://www.jfcinnovations.com/curfloo ) # and produce BSD fortune files from them. # curfloo produces chatlogs in the format: # [DD/MM/YYYY hh:mm:ss] name: comment # where DD=day, MM=month, YYYY=year, hh=hour, mm=minutes, ss=seconds, # name=chat name, comment=text from name in chat # fortune files have the format: # % # text # -- author # The .dat file that accompanies each fortune file is created # by executing strfile [fortune file] # Note that massive manual editing of the logs may be needed # to avoid having fortunes that output nothing more than, # for example, "lol". # ---------------------------------------------------------------------- # default action: # parse $logd/$logn* logs and create 1 file per name under $wdir/$saved/?/name # possible action: # grep 'pattern' in $dir/$name, pipe to awk to parse into 1 filename # first, create a working directory 'wdir' wdir=/opt/test/curfloo/logs/test3 mkdir -p ${wdir} cd ${wdir} saved=atest mkdir -p ${wdir}/${saved} # edit these variables to suit your setup # log directory logd=~/.curfloo/logs # log filenames, note the name will have a '*' tacked on # in the routine that looks for files, so that all files # that _begin_ with what you put here will be processed logn=chatlog. # there's gotta be a better way to get these directories created dlist="junk 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t \ u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z" for d in ${dlist} do mkdir -p ${saved}/${d} done # let the crunching begin cnt=0 cnt=$(($cnt)) for n in ${logd}/${logn}* do # pad a counter with zeros, to use in filenames later count=${cnt} if [ ${cnt} -lt 100 ] then count=0${cnt} fi if [ ${cnt} -lt 10 ] then count=0${count} fi # give some user feedback: the count and the full path and filename echo ${cnt} echo ${n} # process with sed to create records separated by %%%, which helps awk later # sed checks for lines that begin with [DD/MM/YYYY hh:mm:ss] and # substitutes %%%DD/MM/YYYY hh:mm:ss then pipes it to awk, # which uses %%% as a record separator because many chat comments # extend across multiple lines. normally, awk uses newline for a # record separator sed 's/^\[\([0-9]\{2\}\/[0-9]\{2\}\/[0-9]\{4\} [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\)\]/%%%\1/g' ${n} | \ awk -v names=${saved} 'BEGIN { FS=" " RS="%%%" OFS="" ORS="" # maximum allowed line length for output linelen=72 # date field, time field, name field, comment field # datef needs no processing to yield datevar # timef needs no processing to yield timevar # namef gets : stripped from it to yield namevar, # com_f is parsed to produce comment # # fields: datef=1 timef=2 namef=3 com_f=4 # bugs? what bugs? # you mean "features" or "issues", of course. debug=1 } { if (NF >= com_f) { comment="" nodate=substr($0, index($0, $namef)) # strip the : off the name in namef namevar=substr($0, index($0,$timef) + length($timef) + 1, match(nodate,/:/) - 1) namedir=substr(namevar, 1, 1) if (namedir < "0" || ((namedir > "Z") && (namedir < "a")) || namedir > "z") { namedir="junk" } namev_f=namevar gsub(/ /,"_",namev_f) gsub(/\[/,"_",namev_f) gsub(/\//,"_",namev_f) # gsub(/]/,"_",namev_f) gsub(/ startline)) { testpos-- curchar=substr(lastvar,testpos,1) testcom=substr(comment,1,testpos) if (curchar == " ") { pos=testpos comment=testcom comment=substr(comment,1,pos) pos++ } } if (substr(lastvar,pos,1)==" ") { pos++ } comment=comment "\n" ++linecnt } } } if(debug){ print "%\n" comment "\t\t -- " namevar "\n\t\t " datevar " " timevar "\n" } p_out = "%\n" comment "\t\t -- " namevar "\n\t\t " datevar " " timevar "\n" print p_out >> f_name close(f_name) } }' cnt=$(($cnt+1)) done