1

入力-file1.txt

abc message=sent session:111,x,y,z
pqr message=receive session:111,4,5,7
abc message=sent session:123,x,y,z
pqr message=receive session:123,4,5,7
pqr message=receive session:123,4x,5x,7x
pqr message=receive session:123,4p,5q,7r
abc message=sent session:342,x,y,z
abc message=receive session:311,x,y,z
abc message=sent session:589,x,y,z
pqr message=receive session:589,4,5,7

出力

abc message=sent session:111,x,y,z,pqr message=receive session:111,4,5,7
abc message=sent session:123,x,y,z,pqr message=receive session:123,4,5,7,pqr message=receive session:123,4x,5x,7x,pqr message=receive session:123,4p,5q,7r
abc message=sent session:342,x,y,z,NOMATCH
abc message=receive session:311,x,y,z,NOMATCH
abc message=sent session:589,x,y,pqr message=receive session:589,4,5,7

ノート:

  1. 送信済みとその即時受信を検索-MATCHINGセッション番号のみ
  2. すべてのセッション一致「受信」を同じ「送信」と組み合わせます。例:session:123
  3. 「受信」がない場合は、NOMATCHを印刷します
4

2 に答える 2

2

これを試して:

awk -F "[:,]"  '{split($2,a,",");if($1~/sent/){if(prev!~/receive/&& NR!=1)print prev,"NOMATCH";else if (NR!=1)print prev;prev=$0;session=a[1];}if($1~/receive/&&session==a[1]){prev=prev","$0;}}'END'{if(prev~/receive/)print prev;}' file1.txt
于 2013-03-06T05:50:00.747 に答える
1
awk '{x=substr($3,0,match($3,","));a[x]?a[x]=a[x]","$0:a[x]=$0}END{for(i in a){print a[i],a[i]~/sent/&&a[i]~/receive/?"":"NOMATCH"}}' your_file

テスト済み:

>cat temp
abc message=sent session:111,x,y,z
pqr message=receive session:111,4,5,7
abc message=sent session:123,x,y,z
pqr message=receive session:123,4,5,7
pqr message=receive session:123,4x,5x,7x
pqr message=receive session:123,4p,5q,7r
abc message=sent session:342,x,y,z
abc message=receive session:311,x,y,z
abc message=sent session:589,x,y,z
pqr message=receive session:589,4,5,7
> 
> 
> 
> awk '{x=substr($3,0,match($3,","));a[x]?a[x]=a[x]","$0:a[x]=$0}END{for(i in a){print a[i],a[i]~/sent/&&a[i]~/receive/?"":"NOMATCH"}}' temp
abc message=sent session:111,x,y,z,pqr message=receive session:111,4,5,7 
abc message=sent session:123,x,y,z,pqr message=receive session:123,4,5,7,pqr message=receive session:123,4x,5x,7x,pqr message=receive session:123,4p,5q,7r 
abc message=receive session:311,x,y,z NOMATCH
abc message=sent session:589,x,y,z,pqr message=receive session:589,4,5,7 
abc message=sent session:342,x,y,z NOMATCH
> 
于 2013-03-06T06:14:06.580 に答える