这是我的脚本:
#!/bin/bash
for i in *.csv
do
echo "i: $i"
THE_FILE2="$i-2.csv"
file_read()
{
lineno=0
while read line
do
echo $line | awk -F, '{print $1","$2",,,"$3","$4}'
((lineno++))
done
} < $i > $THE_FILE2
echo "the_file2: $THE_FILE2"
echo "end"
done
file_read
输出:
i: 2992.csv
the_file2: 2992.csv-2.csv
end
i: 5415.csv
the_file2: 5415.csv-2.csv
end
i: csa.csv
the_file2: csa.csv-2.csv
end
i: loc.csv
the_file2: loc.csv-2.csv
end
i: visa.csv
the_file2: visa.csv-2.csv
end
$ ls
2992.csv csa.csv transform.sh visa.csv-2.csv
5415.csv loc.csv visa.csv
不幸的是,它只对列表中的最后一个文件执行此操作。它跳过了所有其他的。我有一种感觉,这与缓冲或通配或其他东西有关。我错过了什么?