Ho bisogno di aiuto in quello che a che fare con uno script bash? Sto cercando di eseguire un comando per l'output dei dati da una tabella e poi inserirlo in comandi. Looping per ogni riga di dati.
Ad esempio, l'output di dati da una tabella:
Codice:
10 John house
20 Jane apt
30 Joe townhome
Poi ho bisogno di prendere l'output di dati e di inserirlo in un altro comando, così per esempio il mio output sarà simile:
Codice:
-----
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
Il codice che ho è il seguente:
Codice:
#!/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
L'output è il seguente:
Codice:
-----------------------------------------------------------------
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
----------------------------------------------------------------
Can anyone help me o il punto dove andare su come farlo?
Grazie!