buddylistgrapher
annotate graph_sh.sh @ 11:3af263aed951
cleanups in sed variant
author | meillo@marmaro.de |
---|---|
date | Sat, 09 Jun 2007 00:26:35 +0200 |
parents | 6c327ae23d2c |
children |
rev | line source |
---|---|
meillo@0 | 1 #!/bin/bash |
meillo@0 | 2 # |
meillo@0 | 3 # Autor: Julian Forster (www.ProgMaschine.de.vu) |
meillo@0 | 4 # Autor: markus schnalke (prog.marmaro.de) |
meillo@0 | 5 # |
meillo@0 | 6 |
meillo@0 | 7 |
meillo@0 | 8 if [ $# -eq 1 ]; then |
meillo@0 | 9 if [ $1 = '--version' ] ; then |
meillo@2 | 10 echo 'Buddylistgrapher (shell)' |
meillo@2 | 11 echo '========================' |
meillo@2 | 12 echo 'version 0.2' |
meillo@2 | 13 echo |
meillo@2 | 14 echo 'by Julian Forster (http://progmaschine.de.vu)' |
meillo@2 | 15 echo 'and Markus Schnalke (http://prog.marmaro.de)' |
meillo@2 | 16 exit 0 |
meillo@2 | 17 elif [ $1 = '--help' ] ; then |
meillo@2 | 18 echo 'Buddylistgrapher (shell)' |
meillo@2 | 19 echo '========================' |
meillo@2 | 20 echo |
meillo@2 | 21 echo "usage: $0 <input.txt>" |
meillo@2 | 22 echo |
meillo@2 | 23 echo "The grapher generates output to stdout." |
meillo@2 | 24 echo "This output is the input for the graphviz tools." |
meillo@2 | 25 echo |
meillo@2 | 26 echo "You can use it like this:" |
meillo@2 | 27 echo "$0 input.txt | dot -Tpng > pic.png" |
meillo@2 | 28 echo |
meillo@2 | 29 echo "ToDo:" |
meillo@2 | 30 echo "The program was written for one specific kind of input data," |
meillo@2 | 31 echo "so there is still some work to do to use it for general input." |
meillo@0 | 32 exit 0 |
meillo@0 | 33 else |
meillo@0 | 34 |
meillo@0 | 35 file=/tmp/`basename $0`-$$ |
meillo@0 | 36 file2=/tmp/`basename $0`-$$-2 |
meillo@0 | 37 |
meillo@0 | 38 # extract all needed lines |
meillo@0 | 39 grep -e "Profil von:" -e "Nachricht schreiben" $1 > $file |
meillo@0 | 40 |
meillo@2 | 41 |
meillo@0 | 42 # collect all profil names (we only want them as nodes) |
meillo@0 | 43 cat $file | while read line ; do |
meillo@0 | 44 echo -n "`echo $line | grep "Profil von:" | awk '{print " " $3 " "}'`" >> $file2 |
meillo@0 | 45 done |
meillo@0 | 46 echo >> $file2 |
meillo@0 | 47 |
meillo@0 | 48 |
meillo@0 | 49 # output |
meillo@0 | 50 echo "digraph G {" |
meillo@0 | 51 |
meillo@0 | 52 cat $file | while read line ; do |
meillo@2 | 53 if [ -n "`echo $line | grep "Profil von:"`" ] ; then |
meillo@0 | 54 name=$(echo $line | awk '{ print $3 }') |
meillo@0 | 55 else |
meillo@0 | 56 buddy=$(echo $line | awk '{ print $3 }') |
meillo@0 | 57 if [ -n "`grep -F " $buddy " $file2`" ] ; then |
meillo@0 | 58 echo " \"$name\" -> \"$buddy\";" |
meillo@0 | 59 fi |
meillo@0 | 60 fi |
meillo@0 | 61 done |
meillo@0 | 62 |
meillo@0 | 63 echo "}" |
meillo@0 | 64 |
meillo@2 | 65 rm $file $file2 |
meillo@0 | 66 exit 0 |
meillo@0 | 67 |
meillo@0 | 68 fi |
meillo@0 | 69 else |
meillo@0 | 70 echo "usage: $0 <input.txt>" |
meillo@0 | 71 exit 1 |
meillo@0 | 72 fi |