trim()
{
    printf "$1" | sed -e 's/^ *//' -e 's/ *$//'
}

getField()
{
    NAME="$1"
    DATA="$2"

    printf "$DATA" | grep "$NAME" > /dev/null 2> /dev/null
    if [ "$?" != "0" ]
    then
        return 1
    fi

    trim `printf "$DATA" | cut -d: -f2`
}

getFields()
{
    NAME=$1
    DATA=$2

    IFS=`printf '\n+'`
    for LINE in $DATA
    do
        VALUE=`getField $NAME $LINE` && printf "%s\n" "$VALUE"
    done
}

count()
{
    if [ "$1" == "" ]
    then
        printf "0"
    else
        RES=`printf "$1\n" | wc -l`
        RES=`trim "$RES"`
        printf "$RES"
    fi
}

subst()
{
    sed -i "s|$1|$2|g" "$3" 2> /dev/null || sed -i "" "s|$1|$2|g" "$3"
}