buddylistgrapher

view graph2.sh @ 14:3baea9ea9103

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