
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
4503trans_id
substr($4,0,4)
4503
a
off_id
산출:
4503 3
4513 2
4543 2
4553 2