buddylistgrapher

diff graph2.sh @ 0:21d9547ef242

initial commit C++ and sh editions work similar
author meillo@marmaro.de
date Mon, 28 May 2007 17:41:28 +0200
parents
children 6c327ae23d2c
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/graph2.sh	Mon May 28 17:41:28 2007 +0200
     1.3 @@ -0,0 +1,56 @@
     1.4 +#!/bin/bash
     1.5 +# 
     1.6 +# Autor: Julian Forster (www.ProgMaschine.de.vu)
     1.7 +# Autor: markus schnalke (prog.marmaro.de)
     1.8 +#
     1.9 +
    1.10 +
    1.11 +if [ $# -eq 1 ]; then
    1.12 +  if [ $1 = '--version' ] ; then
    1.13 +    echo 'Buddylistgrapher'
    1.14 +    echo 'shellscript edition'
    1.15 +    echo 'version 0.1'
    1.16 +    exit 0
    1.17 +  else
    1.18 +
    1.19 +    file=/tmp/`basename $0`-$$
    1.20 +    file2=/tmp/`basename $0`-$$-2
    1.21 +
    1.22 +    # extract all needed lines
    1.23 +    grep -e "Profil von:" -e "Nachricht schreiben" $1 > $file
    1.24 +
    1.25 +    # collect all profil names (we only want them as nodes)
    1.26 +    cat $file | while read line ; do
    1.27 +      echo -n "`echo $line | grep "Profil von:" | awk '{print " " $3 " "}'`" >> $file2
    1.28 +    done
    1.29 +    echo >> $file2
    1.30 +
    1.31 +#cat $file2
    1.32 +#exit 
    1.33 +
    1.34 +
    1.35 +    # output
    1.36 +    echo "digraph G {"
    1.37 +    
    1.38 +    cat $file | while read line ; do
    1.39 +      isProfil=`echo $line | grep "Profil von:"`
    1.40 +      if [ -n "$isProfil" ] ; then
    1.41 +        name=$(echo $line |  awk '{ print $3 }')
    1.42 +      else
    1.43 +        buddy=$(echo $line |  awk '{ print $3 }')
    1.44 +        if [ -n "`grep -F " $buddy " $file2`" ] ; then
    1.45 +          echo "  \"$name\" -> \"$buddy\";"
    1.46 +        fi
    1.47 +      fi    
    1.48 +    done
    1.49 +
    1.50 +    echo "}"
    1.51 +
    1.52 +    #rm $file $file2
    1.53 +    exit 0
    1.54 +
    1.55 +  fi
    1.56 +else
    1.57 +    echo "usage: $0 <input.txt>"
    1.58 +    exit 1
    1.59 +fi