#! /bin/csh -f # # reduce a list of filenames to a couple of title words # goto Setup Help: cat << EOF usage: titles.com /directory or titles.com filelist.txt EOF exit 9 Setup: set tempfile = /tmp/titles_tmp$$ #set tempfile = tempfile set endword if($#argv == 0) goto Help foreach arg ( $* ) if(-d $arg ) then find $arg -type f >! ${tempfile}.filenames endif if(-f $arg ) then # list of files cat $arg >! ${tempfile}.filenames endif if($arg =~ [1-9]*) then set temp = `echo $arg | awk '$1+0>1 && $1+0<30{print $1}'` if("$temp" != "") set slots = "$temp" endif end if(! -e ${tempfile}.filenames) goto Help ################################################# # identify "title" strings from directories cat ${tempfile}.filenames |\ awk -F "[/_.]" '{for(i=1;i<=NF;++i) printf "%s ", $i; print ""}' |\ cat >! ${tempfile}.words set words = `awk '{print NF}' ${tempfile}.words | sort -n | tail -1` foreach word ( `echo $words | awk '{for(i=0;i<$1;++i) print i}'` ) @ endword = ( $word + 1 ) set mult = `sort -u +$word -$endword ${tempfile}.words | wc -l` if($mult > 1) break end #cat ${tempfile}.words # use first non-universal directory name set titles = `awk -v word=$endword '! seen[$word]{print $word;++seen[$word]}' ${tempfile}.words` # use third directory name set titles = `awk '! seen[$3]{++count[$3]} {print $3; ++seen[$3]}' ${tempfile}.words` # use 2 most popular directory names set titles = `awk '/OVERWRITTEN/{next} $1!~/data/{++count[$1];next} $2!~/user$/ && $2!="sibyls"{++count[$2];next} $3!~/^uc[sb]/ {++count[$3];next} {++count[$4]} END{for(title in count) print count[title], title}' ${tempfile}.words | sort -nr | awk '{print $NF}' | head -2` if( "$titles" == "") then # use third directory name set titles = `awk '! seen[$3]{++count[$3]} {print $3; ++seen[$3]}' ${tempfile}.words | sort -u` endif # capitalize the first letter set titles = `echo $titles | awk '{for(i=1;i<=NF;++i) print toupper(substr($i,1,1)) substr($i,2)}'` echo "$titles" rm -f ${tempfile}.filenames >& /dev/null rm -f ${tempfile}.words >& /dev/null exit