|
Loop колонке вывода
Мне нужна помощь в том, что делать с Баш скрипт? Я пытаюсь запустить команду для вывода данных из таблицы, а затем вставить его в команду. Looping для каждого ряда данных.
Например, вывод данных из таблицы:
Код:
10 John house
20 Jane apt
30 Joe townhome
Тогда я должен взять на выходе из данных, и вставить его в другую команду, так и для примера вывод будет выглядеть следующим образом:
Код:
-----
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
Код я это:
Код:
#!/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
Результатом является:
Код:
-----------------------------------------------------------------
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
----------------------------------------------------------------
Может ли кто-нибудь поможет мне или точку, куда идти о том, как это сделать?
Спасибо!
|