aff_id=752&off_id=4503trans_id=acacthf60cxr
aff_id=752&off_id=4553trans_id=acacthf60cxr
aff_id=752&off_id=4543trans_id=acacthf60cxr
aff_id=752&off_id=4543trans_id=acacthf60cxr
aff_id=752&off_id=4553trans_id=acacthf60cxr
aff_id=752&off_id=4503trans_id=acacthf60cxr
aff_id=752&off_id=4513trans_id=acacthf60cxr
aff_id=752&off_id=4513trans_id=acacthf60cxr
aff_id=752&off_id=4503trans_id=acacthf60cxr
これは、同じaff_idとは異なる「off_id」を持つ私のファイル形式です。 「off_id」に基づいて数を取り出す必要があります。
ベストアンサー1
アッ解決策:
awk -F'[=&]' '{ a[substr($4,0,4)]++ }END{ for(i in a) print i,a[i] }' file
-F'[=&]'
- 複雑なフィールド区切り記号a[substr($4,0,4)]++
- 値は同様の形式off_id
で4番目のフィールドにあるため、必要な値が抽出されます。配列は、発生回数を値としてインデックス化されます。$4
4503trans_id
substr($4,0,4)
4503
a
off_id
出力:
4503 3
4513 2
4543 2
4553 2