2012-01-11 5 views
0

私は以下の1つの入力ファイルを持っています。unixを使用して特定の列を行単位で印刷するにはどうすればよいですか?

Values,series,setupresultcode,nameofresultcode,resultcode 
2,9184200,,serviceSetupResultempty,2001 
11,9184200,0,successfulReleasedByService,2001 
194,9184200,1,successfulDisconnectedByCallingParty,2001 
101,9184200,2,successfulDisconnectByCalledParty,2001 
2,9184201,0,successfulReleasedByService,2001 
78,9184201,1,successfulDisconnectedByCallingParty,2001 
32,9184201,2,successfulDisconnectByCalledParty,2001 
4,9184202,0,successfulReleasedByService,2001 
63,9184202,1,successfulDisconnectedByCallingParty,2001 
37,9184202,2,successfulDisconnectByCalledParty,2001 

下記のように私は出力をしたい:

Series,successfulReleasedByService,successfulDisconnectedByCallingParty,successfulDisconnectByCalledParty,serviceSetupResultempty 
9184200,11,194,101,2 
9184202,4,63,37, 

series.i.eの共通の印刷値としてシリーズを保管してください。結果ファイルの第1列.i.e入力ファイルの第3(整数)または第4列(文字列)列。

たとえば、データの2番目の列にはn個の系列があります。そのシリーズは4つのsetupresultcode(空、0,1,2)を持っています。各結果コードの名前は第4列に記載されています。 resultcodeが0の場合は印刷したい。すなわちSuccessReleasedByServiceは、シリーズ9184200に対して値11を出力します。

+1

申し訳ありませんのようなものをもたらすであろう私は変換の論理を理解していません。拡大して詳細を深く説明できますか? – Benoit

+0

@gyrousは 'unique(setupresultcode)'の値を列見出しに、 'ユニーク(系列)'を行に、そして各行と列の対に対応する 'Vales'をリストしたいと思います。 –

+0

申し訳ありませんが、私は混乱しています。 :(私は例を説明しようとしましょう:n個の系列を持つ第2列は9184200を取る。その系列は4個のsetupresultcode(空、0,1,2)を持つ系列。各結果コードの名前は第4列にある。結果コードが0.i.esuccessfulReleasedByServiceの場合は、シリーズ9184200に対して値11を出力します。 – gyrous

答えて

1

これは私がテストしていないものの、何らかの擬似コードと見なされても問題ありません。

#!/bin/awk -f 
BEGIN 
{ 
    number_of_series=0; 
} 
{ 
    #This part will be executed for every line 
    if ($3 =="0" || $3 == "1" || $3 == "2") 
    { 
    for (i=1; i<=number_of_series; i++) 
    { 
     #If the series has already been added 
     if(seriesarray[i] == $2) 
     { 
     #Concat the results 
     seriesarray[$2]=seriesarray[$2]","$1; 
     } 
     #If it's a new series 
     else 
     { 
     number_of_series++; 
     seriesarray[$2]=$1; 
     } 
    } 
    } 
} 
END 
{ 
    #Iterate over the series and print the series id and the concatenated results 
    for (series in seriesarray) 
    { 
    print series, seriesarray[series]; 
    } 
} 

これは、

9184200,11,194,101

9184201,2,78,32

9184202,4,63,37

+0

こんにちはkristofあなたの投稿に感謝します。入力を与える方法について何かを教えてもらえますか?このようなエラーが発生しています。 – gyrous

+0

./test.sh >> <<< /ビン/ nawkのをBEGIN ある:ソース線3で救済 – gyrous

関連する問題