Mercurial > buddylistgrapher
comparison graph2.sh @ 2:6c327ae23d2c
added --help to shell edition
some cleanups
author | meillo@marmaro.de |
---|---|
date | Mon, 28 May 2007 20:03:27 +0200 |
parents | 21d9547ef242 |
children |
comparison
equal
deleted
inserted
replaced
1:8d8b41f7c0bc | 2:6c327ae23d2c |
---|---|
5 # | 5 # |
6 | 6 |
7 | 7 |
8 if [ $# -eq 1 ]; then | 8 if [ $# -eq 1 ]; then |
9 if [ $1 = '--version' ] ; then | 9 if [ $1 = '--version' ] ; then |
10 echo 'Buddylistgrapher' | 10 echo 'Buddylistgrapher (shell)' |
11 echo 'shellscript edition' | 11 echo '========================' |
12 echo 'version 0.1' | 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." | |
13 exit 0 | 32 exit 0 |
14 else | 33 else |
15 | 34 |
16 file=/tmp/`basename $0`-$$ | 35 file=/tmp/`basename $0`-$$ |
17 file2=/tmp/`basename $0`-$$-2 | 36 file2=/tmp/`basename $0`-$$-2 |
18 | 37 |
19 # extract all needed lines | 38 # extract all needed lines |
20 grep -e "Profil von:" -e "Nachricht schreiben" $1 > $file | 39 grep -e "Profil von:" -e "Nachricht schreiben" $1 > $file |
21 | 40 |
41 | |
22 # collect all profil names (we only want them as nodes) | 42 # collect all profil names (we only want them as nodes) |
23 cat $file | while read line ; do | 43 cat $file | while read line ; do |
24 echo -n "`echo $line | grep "Profil von:" | awk '{print " " $3 " "}'`" >> $file2 | 44 echo -n "`echo $line | grep "Profil von:" | awk '{print " " $3 " "}'`" >> $file2 |
25 done | 45 done |
26 echo >> $file2 | 46 echo >> $file2 |
27 | 47 |
28 #cat $file2 | |
29 #exit | |
30 | |
31 | 48 |
32 # output | 49 # output |
33 echo "digraph G {" | 50 echo "digraph G {" |
34 | 51 |
35 cat $file | while read line ; do | 52 cat $file | while read line ; do |
36 isProfil=`echo $line | grep "Profil von:"` | 53 if [ -n "`echo $line | grep "Profil von:"`" ] ; then |
37 if [ -n "$isProfil" ] ; then | |
38 name=$(echo $line | awk '{ print $3 }') | 54 name=$(echo $line | awk '{ print $3 }') |
39 else | 55 else |
40 buddy=$(echo $line | awk '{ print $3 }') | 56 buddy=$(echo $line | awk '{ print $3 }') |
41 if [ -n "`grep -F " $buddy " $file2`" ] ; then | 57 if [ -n "`grep -F " $buddy " $file2`" ] ; then |
42 echo " \"$name\" -> \"$buddy\";" | 58 echo " \"$name\" -> \"$buddy\";" |
44 fi | 60 fi |
45 done | 61 done |
46 | 62 |
47 echo "}" | 63 echo "}" |
48 | 64 |
49 #rm $file $file2 | 65 rm $file $file2 |
50 exit 0 | 66 exit 0 |
51 | 67 |
52 fi | 68 fi |
53 else | 69 else |
54 echo "usage: $0 <input.txt>" | 70 echo "usage: $0 <input.txt>" |