Transpose last column of one file to last row of second file

Hello Everyone,

I'm very new to gawk and I need help transposing the last column a .csv file the last row of another .csv file. The data looks as follow. Your help will be much appreciated.

fromfile.csv

26/02/2013,27/02/2013,28/02/2013,03/03/2013,04/03/2013,05/03/2013,06/03/2013,07/03/2013,10/03/2013,11/03/2013,12/03/2013,13/03/2013,14/03/2013,17/03/2013
0.9153-0.9160,0.9105-0.9112,0.9105-0.9111,0.9080-0.9086,0.9105-0.9111,0.9080-0.9086,0.9129-0.9135,0.9227-0.9233,0.9227-0.9233,0.9153-0.9159,0.9133-0.9139,0.9133-0.9139,0.9179-0.9185,0.9153-0.9159
0.9129-0.9136,0.9080-0.9087,0.9080-0.9086,0.9044-0.9050,0.9080-0.9086,0.9044-0.9050,0.9105-0.9111,0.9204-0.9210,0.9204-0.9210,0.9133-0.9139,0.9111-0.9117,0.9111-0.9117,0.9153-0.9159,0.9133-0.9139
0.9105-0.9112,0.9044-0.9051,0.9044-0.9050,0.9026-0.9032,0.9044-0.9050,0.9026-0.9032,0.9080-0.9086,0.9179-0.9185,0.9179-0.9185,0.9111-0.9117,0.9087-0.9093,0.9087-0.9093,0.9133-0.9139,0.9103-0.9109
0.9080-0.9087,0.9026-0.9033,0.9026-0.9032,0.8989-0.8995,0.9026-0.9032,0.8989-0.8995,0.9044-0.9050,0.9153-0.9159,0.9153-0.9159,0.9087-0.9093,0.9051-0.9057,0.9051-0.9057,0.9103-0.9109,0.9076-0.9082
0.9044-0.9051,0.8997-0.9004,0.8997-0.9003,0.8960-0.8966,0.8989-0.8995,0.8969-0.8975,0.9026-0.9032,0.9113-0.9119,0.9113-0.9119,0.9063-0.9069,0.9032-0.9038,0.9032-0.9038,0.9062-0.9068,0.9049-0.9055
0.9026-0.9033,0.8968-0.8975,0.8971-0.8977,0.8939-0.8945,0.8946-0.8952,0.8946-0.8952,0.8997-0.9003,0.9091-0.9097,0.9097-0.9103,0.9034-0.9040,0.8997-0.9003,0.8993-0.8999,0.9042-0.9048,0.9030-0.9036
0.8999-0.9006,0.8940-0.8947,0.8949-0.8955,0.8912-0.8918,0.8925-0.8931,0.8927-0.8933,0.8970-0.8976,0.9060-0.9066,0.9075-0.9081,0.9008-0.9014,0.8958-0.8964,0.8959-0.8965,0.9013-0.9019,0.8993-0.8999
0.8966-0.8973,0.8901-0.8908,0.8924-0.8930,0.8869-0.8875,0.8887-0.8893,0.8906-0.8912,0.8933-0.8939,0.9031-0.9037,0.9031-0.9037,0.8969-0.8975,0.8933-0.8939,0.8920-0.8926,0.8983-0.8989,0.8959-0.8965
0.8935-0.8942,0.8869-0.8876,0.8899-0.8905,0.8824-0.8830,0.8869-0.8875,0.8887-0.8893,0.8906-0.8912,0.9001-0.9007,0.9001-0.9007,0.8933-0.8939,0.8906-0.8912,0.8887-0.8893,0.8959-0.8965,0.8920-0.8926
0.8901-0.8908,0.8824-0.8831,0.8869-0.8875,0.8796-0.8802,0.8824-0.8830,0.8869-0.8875,0.8887-0.8893,0.8969-0.8975,0.8969-0.8975,0.8906-0.8912,0.8887-0.8893,0.8869-0.8875,0.8920-0.8926,0.8887-0.8893
0.8869-0.8876,0.8796-0.8803,0.8824-0.8830,0.8768-0.8774,0.8796-0.8802,0.8824-0.8830,0.8869-0.8875,0.8933-0.8939,0.8933-0.8939,0.8887-0.8893,0.8869-0.8875,0.8846-0.8852,0.8887-0.8893,0.8869-0.8875
0.8824-0.8831,0.8768-0.8775,0.8796-0.8802,0.8727-0.8733,0.8768-0.8774,0.8796-0.8802,0.8846-0.8852,0.8906-0.8912,0.8906-0.8912,0.8869-0.8875,0.8846-0.8852,0.8824-0.8830,0.8869-0.8875,0.8846-0.8852

"Desired" tofile.csv

10/03/2013,0.9227-0.9233,0.9204-0.9210,0.9179-0.9185,0.9153-0.9159,0.9113-0.9119,0.9097-0.9103,0.9075-0.9081,0.9031-0.9037,0.9001-0.9007,0.8969-0.8975,0.8933-0.8939,0.8906-0.8912
11/03/2013,0.9153-0.9159,0.9133-0.9139,0.9111-0.9117,0.9087-0.9093,0.9063-0.9069,0.9034-0.9040,0.9008-0.9014,0.8969-0.8975,0.8933-0.8939,0.8906-0.8912,0.8887-0.8893,0.8869-0.8875
12/03/2013,0.9133-0.9139,0.9111-0.9117,0.9087-0.9093,0.9051-0.9057,0.9032-0.9038,0.8997-0.9003,0.8958-0.8964,0.8933-0.8939,0.8906-0.8912,0.8887-0.8893,0.8869-0.8875,0.8846-0.8852
13/03/2013,0.9133-0.9139,0.9111-0.9117,0.9087-0.9093,0.9051-0.9057,0.9032-0.9038,0.8993-0.8999,0.8959-0.8965,0.8920-0.8926,0.8887-0.8893,0.8869-0.8875,0.8846-0.8852,0.8824-0.8830
14/03/2013,0.9179-0.9185,0.9153-0.9159,0.9133-0.9139,0.9103-0.9109,0.9062-0.9068,0.9042-0.9048,0.9013-0.9019,0.8983-0.8989,0.8959-0.8965,0.8920-0.8926,0.8887-0.8893,0.8869-0.8875
17/03/2013,0.9153-0.9159,0.9133-0.9139,0.9103-0.9109,0.9076-0.9082,0.9049-0.9055,0.9030-0.9036,0.8993-0.8999,0.8959-0.8965,0.8920-0.8926,0.8887-0.8893,0.8869-0.8875,0.8846-0.8852

The need is just to transpose the last column from one file (fromfile.csv) to last row of the second file (the desired tofile.csv)

I have searched through the forum however I could not locate any relevant post, if this kind of query has already been posted before, please accept my sincere apologies.

Untested

awk '{
      for(i=1;i<=NF;i++)
      A = A ? A OFS $i : $i
     }
  END{
	for(i=1;i<=NF;i++)
	print A
     }' FS=',' OFS=',' file
awk 'BEGIN{FS = OFS = ","}
 {a[NR] = $NF}
 END {for(i = 1; i <= length(a); i++)
  {out = (out == "") ? a : (out OFS a)};
 print out}' fromfile.csv >> tofile.csv

Though I could not test code for some reason, I can see that you have modified your input, here is original input you have posted, don't do like this again in future.,

$ cat foo
10/03/2013,11/03/2013,12/03/2013,13/03/2013,14/03/2013,17/03/2013
0.9227-0.9233,0.9153-0.9159,0.9133-0.9139,0.9133-0.9139,0.9179-0.9185,0.9153-0.9159
0.9204-0.9210,0.9133-0.9139,0.9111-0.9117,0.9111-0.9117,0.9153-0.9159,0.9133-0.9139
0.9179-0.9185,0.9111-0.9117,0.9087-0.9093,0.9087-0.9093,0.9133-0.9139,0.9103-0.9109
0.9153-0.9159,0.9087-0.9093,0.9051-0.9057,0.9051-0.9057,0.9103-0.9109,0.9076-0.9082
0.9113-0.9119,0.9063-0.9069,0.9032-0.9038,0.9032-0.9038,0.9062-0.9068,0.9049-0.9055
0.9097-0.9103,0.9034-0.9040,0.8997-0.9003,0.8993-0.8999,0.9042-0.9048,0.9030-0.9036
0.9075-0.9081,0.9008-0.9014,0.8958-0.8964,0.8959-0.8965,0.9013-0.9019,0.8993-0.8999
0.9031-0.9037,0.8969-0.8975,0.8933-0.8939,0.8920-0.8926,0.8983-0.8989,0.8959-0.8965
0.9001-0.9007,0.8933-0.8939,0.8906-0.8912,0.8887-0.8893,0.8959-0.8965,0.8920-0.8926
0.8969-0.8975,0.8906-0.8912,0.8887-0.8893,0.8869-0.8875,0.8920-0.8926,0.8887-0.8893
0.8933-0.8939,0.8887-0.8893,0.8869-0.8875,0.8846-0.8852,0.8887-0.8893,0.8869-0.8875
0.8906-0.8912,0.8869-0.8875,0.8846-0.8852,0.8824-0.8830,0.8869-0.8875,0.8846-0.8852

---------- Post updated at 05:14 PM ---------- Previous update was at 05:12 PM ----------

Assuming your input file has 13 lines:

tr -s ',' '\n' <fromfile.csv | pr -ts, -13 >tofile.csv

Hello Akshay, Apologies for modifying the input file data. I will ensure this is not repeated in future.

Hi SriniShoo,

Thank you for providing the code, I have tested and noticed that the tofile.csv result as follow after adding an additional column in fromfile.csv.

10/03/2013,0.9227-0.9233,0.9204-0.9210,0.9179-0.9185,0.9153-0.9159,0.9113-0.9119,0.9097-0.9103,0.9075-0.9081,0.9031-0.9037,0.9001-0.9007,0.8969-0.8975,0.8933-0.8939,0.8906-0.8912
11/03/2013,0.9153-0.9159,0.9133-0.9139,0.9111-0.9117,0.9087-0.9093,0.9063-0.9069,0.9034-0.9040,0.9008-0.9014,0.8969-0.8975,0.8933-0.8939,0.8906-0.8912,0.8887-0.8893,0.8869-0.8875
12/03/2013,0.9133-0.9139,0.9111-0.9117,0.9087-0.9093,0.9051-0.9057,0.9032-0.9038,0.8997-0.9003,0.8958-0.8964,0.8933-0.8939,0.8906-0.8912,0.8887-0.8893,0.8869-0.8875,0.8846-0.8852
13/03/2013,0.9133-0.9139,0.9111-0.9117,0.9087-0.9093,0.9051-0.9057,0.9032-0.9038,0.8993-0.8999,0.8959-0.8965,0.8920-0.8926,0.8887-0.8893,0.8869-0.8875,0.8846-0.8852,0.8824-0.8830
14/03/2013,0.9179-0.9185,0.9153-0.9159,0.9133-0.9139,0.9103-0.9109,0.9062-0.9068,0.9042-0.9048,0.9013-0.9019,0.8983-0.8989,0.8959-0.8965,0.8920-0.8926,0.8887-0.8893,0.8869-0.8875
17/03/2013,0.9153-0.9159,0.9133-0.9139,0.9103-0.9109,0.9076-0.9082,0.9049-0.9055,0.9030-0.9036,0.8993-0.8999,0.8959-0.8965,0.8920-0.8926,0.8887-0.8893,0.8869-0.8875,0.8846-0.8852
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
,,,,,,,,,,,,
18/03/2013
,1.1-1.2
,1.1-1.2
,1.1-1.2
,1.1-1.2
,1.1-1.2
,1.1-1.2
,1.1-1.2
,1.1-1.2
,1.1-1.2
,1.1-1.2
,1.1-1.2
,1.1-1.2