複数の列から一意の文字列を数え、それらの数のみを表示するにはどうすればよいですかawk
私の入力ファイルc.txt
:
US A one
IN A two
US B one
LK C one
US B two
US A three
IN A three
US B one
LK C two
US B three
US A one
IN A one
US B three
LK C three
US B two
US A two
IN A two
US B two
LK C three
US B two
US A one
IN A two
US B one
LK C one
US B two
US A three
IN A three
US B one
LK C two
US B three
US A one
IN A one
US B three
LK C three
US B two
US A two
IN A two
US B two
LK C three
US B two
US A one
IN A two
US B one
LK C one
US B two
US A three
IN A three
US B one
LK C two
US B three
US A one
IN A one
US B three
LK C three
US B two
US A two
IN A two
US B two
LK C three
US B two
US A one
IN A two
US B one
LK C one
US B two
US A three
IN A three
US B one
LK C two
US B three
US A one
IN A one
US B three
LK C three
US B two
US A two
IN A two
US B two
LK C three
US B two
US A one
IN A two
US B one
LK C one
US B two
US A three
IN A three
US B one
LK C two
US B three
US A one
IN A one
US B three
LK C three
US B two
US A two
IN A two
US B two
LK C three
US B two
私はこれを達成できましたが、3つのコマンドで別々に、単一のコマンドですべての出力を取得することは可能ですか?
awk '{a[$1]++}END{for (i in a)print i,a[i]}' c.txt
awk '{a[$1" "$2]++}END{for (i in a)print i,a[i]}' c.txt
awk '{a[$1" "$2" "$3]++}END{for (i in a)print i,a[i]}' c.txt
私の望ましい出力は次のとおりです。
IN 20 A 20 one 5
IN 20 A 20 three 5
IN 20 A 20 two 10
LK 20 C 20 one 5
LK 20 C 20 three 10
LK 20 C 20 two 5
US 60 A 20 one 10
US 60 A 20 three 5
US 60 A 20 two 5
US 60 B 40 one 10
US 60 B 40 three 10
US 60 B 40 two 20
2 列目は、入力ファイルの 1 列目の一意の値の合計です。
4 列目は、入力ファイルの 1 列目と 2 列目の一意の値の合計です。
6 列目は、入力ファイルの 1 列目、2 列目、3 列目の合計 Uniq 値です。