ADD DATA IN LINUX

0

How can I do to subtract the values of the number of tickets sold per event to the total number of seats in each tribune of the event to know the seats available for that event?

function menu
{
  echo "MENU PRINCIPAL"
  echo "1. Consultas"
  echo "2. Ingresar nueva venta"
  echo "0. Salir"
}

Opcion=1
while [ $Opcion -ne 0 ]
do
  clear
  menu
  read -p "Ingrese una opcion: " Opcion
  case $Opcion in
    1) sh MenuConsultas.sh
    ;;
    2) sh IngresarVenta.sh
    ;;
    0) echo "Hasta luego"
    ;;
    *) echo "Opcion incorrecta"
      Opcion=1
      read -p "Presione enter para continuar" enter
      ;;
  esac
done

function ingresar
{
  echo "Ingrese la fecha del evento: "
  read fecha
  echo "Ingrese el nombre del evento: "
  read nombre
  echo "Ingrese la ubicacion: "
  read ubicacion
  echo "Ingrese el valor: "
  read valor
  echo "Ingrese C.I: "
  read ci

  echo "$fecha - $nombre - $ubicacion - $valor - $ci" >> EntradasVendidas.txt
}

echo "Ingrese 1 para registrar una nueva venta. Ingrese 2 para volver al menu principal"

case $opcion in
  1) ingresar
  ;;
  2) sh MenuPrincipal.sh
  ;;
  *) echo "Opcion incorrecta. Se volvera al menu principal"
  sh MenuPrincipal.sh
  ;;
esac

function menu
{
  echo "MENU CONSULTAS"
  echo "1. Entradas vendidas por evento"
  echo "2. Entradas disponibles por evento"
  echo "0. Volver al menu principal"
}

Opcion=1
while [ $Opcion -ne 0 ]
do
  clear
  menu
  read -p "Ingrese una opcion: " Opcion
  case $Opcion in
    1) sh EntradasVendidasPorEvento.sh
    ;;
    2) sh EntradasDisponiblesPorEvento.sh
    ;;
    0) sh MenuPrincipal.sh
    ;;
    *) echo "Opcion incorrecta"
      Opcion=1
      read -p "Presione enter para continuar" enter
      ;;
  esac
done

echo "Ingrese el nombre del evento: "
read evento
echo "Cantidad de entradas vendidas para $evento: "
grep -i "$evento" EntradasVendidas.txt | wc -l
    
asked by Melannie Nichole 03.11.2018 в 02:47
source

1 answer

0

It would be necessary to enter by variable or in a file the total number that we will have before making the query.

We have a file where we store those that we sell:

EntradasVendidas.txt

We will generate a variable or a file in which we will have the total of entries for each event:

File:

EntradasTotales.txt

Variable:

TOTALES=50

We will have to do the following to perform the subtraction, defining the values with variables:

VENDIDAS='grep -i "$evento" EntradasVendidas.txt | wc -l'
TOTALES='grep -i "$evento" EntradasTotales.txt | wc -l'

DISP='expr ${TOTALES} - ${VENDIDAS}'

echo "Tenemos un total de ${DISP} entradas disponibles para ${evento}

In case of having the totals in a variable instead of a file, we would have to simply change that line.

    
answered by 20.12.2018 в 23:21