J'ai besoin d'aide dans ce qu'il faut faire avec un script bash? J'essaie d'utiliser une commande pour la production des données d'une table, puis l'insérer dans les commandes. Looping pour chaque ligne de données.
Par exemple, la production des données d'un tableau:
Code:
10 John house
20 Jane apt
30 Joe townhome
Ensuite, j'ai besoin de prendre la sortie à partir des données et de l'insérer dans une autre commande, afin par exemple ma sortie ressemblera à:
Code:
-----
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
Le code que j'ai est:
Code:
#!/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 sortie est:
Code:
-----------------------------------------------------------------
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 le cas ou le point d'aller sur la façon de faire?
Merci!