如何将两个文件合并为一个?

时间:2015-09-17 07:23:51

标签: awk

我有2个甚至更多的文件要处理。 文件1:

20150115,6601,30,4303.60,751,9000707480,20141201,TM985761,6870904569,USD,FX0000000000000000000001
20150115,6601,30,4303.60,751,9000707480,20141201,TM951728,6870904569,USD,FX0000000000000000000002

文件2:

20150115,6601,30,2400.00,751,9000707845,20141201,TM960897,6870904569,USD,FX0000000000000000000003
20150115,6601,30,2400.00,751,9000707845,20141201,TM946939,6870904569,USD,FX0000000000000000000004

所以如何将这些文件合并到

文件3:

20150115,6601,30,4303.60,751,9000707480,20141201,TM985761,6870904569,USD,FX0000000000000000000001
20150115,6601,30,4303.60,751,9000707480,20141201,TM951728,6870904569,USD,FX0000000000000000000002
20150115,6601,30,2400.00,751,9000707845,20141201,TM960897,6870904569,USD,FX0000000000000000000003
20150115,6601,30,2400.00,751,9000707845,20141201,TM946939,6870904569,USD,FX0000000000000000000004

到现在为止,我无法使用下面的

处理多个文件
cd /npcs/Rel2A/PROD/inbound/FXCSV/received
for i in `ls -l *.csv.dat | awk '/^-/ {print $NF}'`
do
cp $i /npcs/Rel2A/PROD/inbound/FXCSV/bckp_files/$i.orig
      echo $i
awk -F, '{for(i=1;i<=NF;i++){printf "%-20s", $i};printf "\n"}'  $i  > fxcsv00.dat

请帮助

2 个答案:

答案 0 :(得分:2)

鉴于您发布的样本输入/输出,您只需要:

cat file1 file2 > file3

答案 1 :(得分:1)

您只需要替换&#34;&gt;&#34;使用&#34;&gt;&gt;&#34;

cd /npcs/Rel2A/PROD/inbound/FXCSV/received
for i in `ls -l *.csv.dat | awk '/^-/ {print $NF}'`
do
cp $i /npcs/Rel2A/PROD/inbound/FXCSV/bckp_files/$i.orig
      echo $i
awk -F, '{for(i=1;i<=NF;i++){printf "%-20s", $i};printf "\n"}'  $i  >> fxcsv00.dat
done