【发布时间】:2017-04-06 17:28:08
【问题描述】:
我想根据行中的前几个字符从文件中随机选择行。在我的文件中,前几个字符被命名为“Hybrid:2”、“Hybrid:19”等。我想从每个 Hybrid 类别中随机选择一个代表行。
我有一个格式如下的文件:
Hybrid: 2 Parents: 12 and 49 9.419642 0.000000
Hybrid: 2 Parents: 15 and 49 6.427708 0.000000
Hybrid: 2 Parents: 16 and 49 8.383469 0.000000
Hybrid: 2 Parents: 17 and 49 7.869732 0.000000
Hybrid: 19 Parents: 2 and 23 6.905067 0.000000
Hybrid: 19 Parents: 2 and 30 7.913185 0.000000
Hybrid: 19 Parents: 2 and 57 10.724088 0.000000
Hybrid: 52 Parents: 2 and 23 9.398697 0.000000
Hybrid: 44 Parents: 2 and 30 7.739156 0.000000
Hybrid: 50 Parents: 2 and 30 10.051190 0.000000
我想制作这样的文件:
Hybrid: 2 Parents: 15 and 49 6.427708 0.000000
Hybrid: 19 Parents: 2 and 23 6.905067 0.000000
Hybrid: 52 Parents: 2 and 23 9.398697 0.000000
Hybrid: 44 Parents: 2 and 30 7.739156 0.000000
Hybrid: 50 Parents: 2 and 30 10.051190 0.000000
我认为 shuf 会很有用,但我不知道如何在这里应用它。我不知道如何处理这个问题,所以任何帮助都将不胜感激!
【问题讨论】:
标签: unix