Ik heb hulp nodig in wat te doen met een bash-script? Ik probeer het uitvoeren van een commando naar de output van de gegevens uit een tabel en vervolgens plaatst u het in commando's. Looping voor elke rij van de gegevens.
Bijvoorbeeld de productie van gegevens uit een tabel:
Code:
10 John house
20 Jane apt
30 Joe townhome
Daarna heb ik nodig om de output van de gegevens en plaats deze in een ander commando, zodat bijvoorbeeld mijn output zou er als volgt uitzien:
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
De code die ik heb is:
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
De output is:
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
----------------------------------------------------------------
Kan iemand me helpen of het punt waar te gaan over hoe dit te doen?
Bedankt!