#! /bin/sh clear while true do echo "New record" maxrecord=`ls -1 *.dat | sort | tail -1 | cut -d. -f 1` newrecord=$(echo $maxrecord + 1 | bc ) width=`echo $newrecord | wc -c` if [ $width -eq 2 ] ; then prefix="000" elif [ $width -eq 3 ]; then prefix="00" elif [ $width -eq 4 ]; then prefix="0" else prefix="" fi newdat=$(echo "$prefix $newrecord.dat") while true do clear echo "Record number $newrecord - $newdat $PWD" echo "------------------------------------------------------------" if [ -e $newdat ]; then cat $newdat fi echo "------------------------------------------------------------" echo -n "Keyükeys: ";read key if [ "$key" = "-" ]; then exit fi clear while true do echo "Record number $newrecord - $newdat $PWD" echo "------------------------------------------------------------" if [ -e $newdat ]; then cat $newdat fi echo "------------------------------------------------------------" echo "Keyükeys: $key" echo -n "Field: ";read field if [ "$field" = "-" ]; then break fi echo -n "Value: ";read value # Assemble variable "input" from the # variables $key (Keyükeys), $field (Field) # and $value (Value) input=$(echo "$key|$field|$value") # Assemble variable "keyfield" from the # variables $key (Keyükeys) and $field (Field) # for comparison keyfield=$(echo "$key|$field|") # The first time through, capture the file # Not yet! if [ -e $newdat ]; then grep -q $keyfield $newdat back=$(echo $?) fi # If the line already exists .... if [ $back -eq 0 ]; then echo "############### Line already exists! #############" grep $keyfield $newdat echo "------------------------------------------------------" echo -n "Replace stored data line (j)? ";read we if [ "$we" = "y" ]; then # Delete line and write to # temporary file # Build sed instruction resp=$(echo "sed '/$keyfield'/d") # Execute with eval cat $newdat | eval $resp > $newdat.tmp # Rename temporary file again mv $newdat.tmp $newdat # Add new data line echo $input >> $newdat fi else echo $input >> $newdat fi clear done # Calculate checksum invoice amount a=`cat $newdat | grep "50|21|" | cut -d\| -f3` b=`cat $newdat | grep "50|25|" | cut -d\| -f3` a=$(echo $a | tr \, \.) b=$(echo $b | tr \, \.) psum=$(echo "$a+$b" | bc ) echo -n "Invoice amount: $psum, continue .....";read we done done