# 个数统计

比如一个文件：

{% code title="original\_file" %}

```bash
a
b
a
c
d
e
a
e
d
a
b
c
a
```

{% endcode %}

每行一个字母，要统计每个字母出现的次数。可以：

```bash
awk '{sum[$0]+=1} END {for(k in sum) print k ":" sum[k]}' original_file
```

结果：

```bash
a:5
b:2
c:2
d:2
e:2
```

当然也可以放进一个脚本中：

{% code title="group\_by.awk" %}

```bash
#! /usr/bin/awk -f
{sum[$0]+=1} END {for(k in sum) print k ":" sum[k]}
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://valineliu.gitbook.io/deuterium-wiki/linux/awk-1/ge-shu-tong-ji.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
