我正在尝试逐行读取包含由句点分隔的字段的输入文件。我想将它们放入一个数组数组中,以便稍后循环遍历它们。输入似乎没问题,但是将其“推送”到数组(inData)上似乎不起作用。
代码如下:
Input file:
GSDB.GOSALESDW_DIST_INVENTORY_FACT.MONTH_KEY
GSDB.GOSALESDW_DIST_INVENTORY_FACT.ORGANIZATION_KEY
infile=${1}
OIFS=$IFS
IFS=":"
cat ${infile} | while read line
do
line=${line//\./:}
inarray=(${line})
# echo ${inarray[@]}
# echo ${#inarray[@]}
# echo ${inarray[0]}
# echo ${inarray[1]}
# echo ${inarray[2]}
inData=("${inData[@]}" "${inarray[@]}")
done
IFS=$OIFS
echo ${#inData[@]}
for ((i = 0; i < ${#inData[@]}; i++))
do
echo $i
for ((j = 0; j < ${#inData[$i][@]}; j++))
do
echo ${inData[$i][$j]}
done
done