从文件中创建一个数组

时间:2017-10-19 09:12:38

标签: sql arrays linux bash

好吧,即时通讯使用bash脚本,现在我在名为" differ2"的文件中输出了一个输出, 该文件包含一些行:

table3 ('13','20', '50');
table4 ('13','20', '50','60','70');
table5 ('13','20');

我需要创建一个数组,该数组采用表的名称而另一个采用值,我想将这些数组放在文件中,以便像这样插入:

INSERT INTO $array_table
VALUES ($array_values);

INSERT INTO $array_table
VALUES ($array_values);

1 个答案:

答案 0 :(得分:0)

l34rn3r@l34rn3r-Aspire-E5-571 /tmp $ cat input.txt 
table3 ('13','20', '50');
table4 ('13','20', '50','60','70');
table5 ('13','20');
l34rn3r@l34rn3r-Aspire-E5-571 /tmp $ awk '{ print "insert into "$1" values ";$1=""; print$0}' input.txt 
insert into table3 values 
 ('13','20', '50');
insert into table4 values 
 ('13','20', '50','60','70');
insert into table5 values 
 ('13','20');