1

I have file like this.. for eg:

number,dac,amountdac,expdate,0
1111,1,0.000000,2010-07-21,0
1111,2,0.000000,2010-07-21,0
1111,3,0.000000,2010-07-21,0
1111,4,0.000000,2010-07-21,0
1111,5,0.000000,2010-07-21,0
1111,6,0.000000,2010-07-21,0
1111,7,0.000000,2010-07-21,0
1111,8,0.000000,2010-07-21,0
1111,9,0.000000,2010-07-21,0
1111,10,0.000000,2010-07-21,0
2222,1,50.000000,2010-07-21,0
2222,2,0.000000,2010-07-21,0
2222,3,0.000000,2010-07-21,0
2222,4,0.000000,2010-07-21,0
2222,5,0.000000,2010-07-21,0
2222,6,0.000000,2010-07-21,0
2222,7,0.000000,2010-07-21,0
2222,8,10.000000,2010-07-21,0
2222,9,0.000000,2010-07-21,0
2222,10,0.000000,2010-07-21,0
3333,1,0.000000,2010-07-21,0
3333,2,0.000000,2010-07-21,0
3333,3,0.000000,2010-07-21,0
3333,4,0.000000,2010-07-21,0
3333,5,0.000000,2010-07-21,0
3333,6,0.000000,2010-07-21,0
3333,7,0.000000,2010-07-21,0
3333,8,0.000000,2010-07-21,0
3333,9,200.000000,2010-07-21,0
3333,10,50.000000,2010-07-21,0

i want output like this, column 1 number is same for all dac1 to dac10. header i gave for your reference. in original file i don't have header.

number,dac1,dac2,dac3,dac4,dac5,dac6,dac7,dac8,dac9,dac10,amountdac1,amountdac2,amountdac3,,amountdac4,amountdac5,amountdac6,amountdac7,amountdac8,amountdac9,,amountdac10,expdate1,expdate2,expdate3,expdate4,expdate5,expdate6,expdate7,expdate8,expdate9,expdate10,0
1111,1,2,3,4,5,6,7,8,9,10,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,0
2222,1,2,3,4,5,6,7,8,9,10,50.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,10.000000,0.000000,0.000000,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,0
3333,1,2,3,4,5,6,7,8,9,10,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,200.000000,50.000000,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,2010-07-21,0
4

3 に答える 3

2
awk -F"," '{ 
   a[$1];
   b[$1]=b[$1]","$2 
   c[$1]=c[$1]","$3
   d[$1]=d[$1]","$4
   e[$1]=e[$1]","$5 }
END{ for(i in a){ print i,b[i],c[i],d[i],e[i] } } ' file
于 2010-07-21T13:03:40.830 に答える
0

それを分割する Python スクリプトを作成できます。

numbers = []
dacs = []
amountdacs = []
expdates = []
for row in text:
    number, dac, amountdac, expdate, zero = row.split(',')
    numbers.append(number)
    dacs.append(dac)
    amountdacs.append(amountdac)
    expdates.append(expdate)
# print things out however you want them

もしあなたが私より簡単に使えるなら、おそらく perl で似たようなことをすることができるでしょう。

于 2010-07-21T12:28:22.667 に答える
0

基本的には、データを転置する必要があると思います。 stackoverflow には同様の質問があり、非常に優れた解決策があります

残っている唯一のタスクは、スクリプト スキルを使用して、

  • データのチャンク、つまり一度に 10 行を取得します。
  • その10行の最初の列を削除し、データを転置します
  • 最初の列の値を追加します (ここでは 1111 または 2222 または 3333)

上記の 3 つの手順はすべて、入力ファイルのすべての行に対して再帰的に実行する必要があります。

ソリューションの半分は提供されていると思いますが、残りの部分は簡単なスクリプトで管理できます。

于 2010-07-21T12:37:26.843 に答える