共通記録確認

共通記録確認

いくつかの履歴をすばやく確認するためにawkが必要な作業があります。

次のように言いましょう。

A1,A2
B1,B2
C1,C2
C2,C1
A1,C1
A1,B1
B1,A1

これは、A#、B#、C#間の相互性のみを確認し、不可逆性のみを出力する最良の方法です。たとえば、上記の内容は次のように出力する必要があります。

A2 -> A1
B2 -> B1

A#はあるグループに属し、B#は別のグループに属します。 A#とC#またはB#の間のどのような接続を見つけることにも興味がありません。代わりに、As、Bs、Csなどのグループ内で検索を維持してください。

ベストアンサー1

あなたの質問が次のように解釈されると仮定すると、Perlの代替案になります。sg-lecram:

perl -lne 'tr{ }{}d;      # Remove whitespace in current line
           $lines{$_}++;  # Record the current line in a hash
           END{           # After all lines have been processed
               for(keys %lines){   # Iterate over hash keys
                 #Skip records with different letters:
                 next unless /([a-z]).*\1/i; 
                 ($first,$second)=split /,/; #Read the two fields
                 #Print the record unless its reciprocal is found:
                 print unless exists $lines{"$second,$first"}; 
           }' your_file

おすすめ記事