Necesito ayuda en lo que se debe hacer con un script bash? Estoy tratando de ejecutar un comando para la salida de los datos de una tabla y, a continuación, insértelo en comandos. Bucle para cada fila de datos.
Por ejemplo, la salida de datos de una tabla:
Código:
10 John house
20 Jane apt
30 Joe townhome
Luego tengo que tomar la salida de los datos e insertarla en otro comando, por lo que, por ejemplo, mi salida se vería como:
Código:
-----
The number of the person is 10
The name of the person is John
John lives in a house
-----
The number of the person is 20
The name of the person is Jane
Jane lives in a apt
-----
The number of the person is 30
The name of the person is Joe
Joe lives in a townhome
El código que tengo es:
Código:
#!/bin/bash
echo
echo "-----------------------------------------------------------------"
DATA=`cat data.txt`
for i in $DATA; do
NUM=$(echo $i |awk '{print $1}');
NAME=$(echo $i |awk '{print $2}');
LOC=$(echo $i |awk '{print $3}');
echo "The number of the person is $NUM"
echo "The name of the person is $NAME"
echo "$NAME lives in a $LOC"
echo
echo "-----------------------------------------------------------------"
echo
done
La salida es:
Código:
-----------------------------------------------------------------
The number of the person is 10
The name of the person is
lives in a
-----------------------------------------------------------------
The number of the person is John
The name of the person is
lives in a
-----------------------------------------------------------------
The number of the person is house
The name of the person is
lives in a
-----------------------------------------------------------------
The number of the person is 20
The name of the person is
lives in a
-----------------------------------------------------------------
The number of the person is Jane
The name of the person is
lives in a
-----------------------------------------------------------------
The number of the person is apt
The name of the person is
lives in a
-----------------------------------------------------------------
The number of the person is 30
The name of the person is
lives in a
-----------------------------------------------------------------
The number of the person is Joe
The name of the person is
lives in a
-----------------------------------------------------------------
The number of the person is townhome
The name of the person is
lives in a
----------------------------------------------------------------
¿Puede alguien me ayuda o el punto donde ir sobre cómo hacer esto?
Gracias!