MERGE 13 files and add the file name at the end of each record

Hi Gurus,
I have 13 comma(,) seperated files that i have to merge and create a single file which has file name attached at th end of each record in the out put file. Can any one please help me with writing a unix script with this issue?

test1.dat
BIG ID,Local ID,Bond Description,Liquidity,Maturity,Mat Sect,Price,Accr Int,Outs-Loc ,MVal-Loc,MVal-USD,MVal-EUR,Mac Dur,Mod Dur,Yield,Convexity,Coupon,Issue Date,Freq,ISIN
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,AT0000384938
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939
 
test2.dat
BIG ID,Local ID,Bond Description,Liquidity,Maturity,Mat Sect,Price,Accr Int,Outs-Loc ,MVal-Loc,MVal-USD,MVal-EUR,Mac Dur,Mod Dur,Yield,Convexity,Coupon,Issue Date,Freq,ISIN
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,AT0000384938
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939
 
test3.dat
BIG ID,Local ID,Bond Description,Liquidity,Maturity,Mat Sect,Price,Accr Int,Outs-Loc ,MVal-Loc,MVal-USD,MVal-EUR,Mac Dur,Mod Dur,Yield,Convexity,Coupon,Issue Date,Freq,ISIN
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,AT0000384938
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939
so on upto thirteen files
 
my output neeeds to be
outputfile.dat
BIG ID,Local ID,Bond Description,Liquidity,Maturity,Mat Sect,Price,Accr Int,Outs-Loc ,MVal-Loc,MVal-USD,MVal-EUR,Mac Dur,Mod Dur,Yield,Convexity,Coupon,Issue Date,Freq,ISIN,FINENAME
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,AT0000384938,test1.dat
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939,test1.dat
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939,test1.dat
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 3',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939,test1.dat
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 6',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,AT0000384938,test2.dat
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 6',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939,test2.dat
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 6',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939,test2.dat
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 6',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939,test2.dat
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 8',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,AT0000384938,test3.dat
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 8',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939,test3.dat
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 8',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939,test3.dat
AAA0024,BBB0024,sync  5.50%  RAGB  Jan  2010,Ben,15-Jan-2008,'1 - 8',101.075,2.87,8809.982,9157.532,14524.303,9157.532,1.427,1.363,4.703,3.205,5.5,22-Oct-1999,1,PT0000384939,test3.dat

 

I appreciate if any one can help me with this issue.
thanks
vkr

try:

awk '{ print $0, FILENAME }'  test*.dat  > outputfile

Won't work if there are any other test<...?>.dat files in the directory thsat you don't want included.

awk '{printf "%s,%s\n",$0,FILENAME}' *.dat >new_filename

1 Like