予期しない値の並べ替えとキャッチ(シェルスクリプト)

予期しない値の並べ替えとキャッチ(シェルスクリプト)

.csv ファイルがあり、3 番目の列には YES および NO 値のみが予想されます。

Sample1|Sample2|YES
Sample1|Sample2|YES
Sample1|Sample2|YES
Sample1|Sample2|YES
Sample1|Sample2|NO
Sample1|Sample2|MAYBE(random*)
Sample1|Sample2|MAYBE(random*)

注:(random*)ここに存在できる任意の値を示します。

したがって、私が望む結果は次のようになります。

Expecting value count: 5
YES = 4
NO = 1

Not expecting value count: 2
MAYBE = 2

YESとNO以外の値がない場合、私が望む出力は次のようになります。

Expecting value count:
YES = 4
NO = 1
Not expecting value count: 0

ベストアンサー1

たぶん、次のようなものがあります。

tr '(' '|' < file | cut -d'|' -f3 | sort | uniq -c

おすすめ記事