将每个第一列元素放在第二列中出现的次数

Put each first column element the number of times that appear on second column

我没有太多使用 Unix 工具的经验,我想知道如何做到这一点:

我有一个包含 2 列的文件(space 选项卡):

Agent 2
Person 3
Place 1
Location 4

第一列的每个不同元素都是一个数字(Agent -> 1Person -> 2Place -> 3Location -> 4)。

因此,我想让每个第一列数字元素出现在第二列的次数。在这种情况下:

1
1
2
2
2
3
4
4
4
4

说明:Agent (1)出现2次,Person (2)出现3次,以此类推

希望你能帮助我。提前致谢。

$ awk '{for (i=1; i<=; i++) print NR}' file
1
1
2
2
2
3
4
4
4
4