查找文件中有多少个不同名称的命令

Command to find how many different name there is in a file

我有一个包含一组孩子 (+5xxx) 的姓名、性别和出生年份的文件,我需要找出有多少个不同的名字。这是文件的示例:

2008 fille Avah     
2008 fille Carleigh     
2008 fille Kenley     
2000 garçon Michael     
2000 garçon Joseph 

我尝试了这个命令 (cat prenoms.txt | cut -c 12-30 |uniq |wc -l),但问题是当我剪切前 12 或 13 行时,它永远不会只给我名字,因为性别是不同大小的单词。谁能帮忙?

提前谢谢你。

使用 space 作为分隔符,如下所示。

$cat sample.txt |cut -d" " -f3 |sort|uniq
Avah
Carleigh
Joseph
Kenley
Michael

或者你可以使用 awk

$awk '{print }' sample.txt |sort|uniq
Avah
Carleigh
Joseph
Kenley
Michael

请尝试并告诉我们结果。干杯