找出文件中重复出现最多的行

#查看第一列的所有数据并导出到1.log文件内
cat test.txt |awk -F ':' '{print $1}' > 1.log
from collections import Counter

# 读取文件内容并计算每一行的出现次数
with open('filename.txt', 'r') as file:
    lines = file.readlines()
    line_count = Counter(lines)

# 找到出现次数最多的行及其出现次数
most_common_line, most_common_count = line_count.most_common(1)[0]

print("出现次数最多的行是:")
print(most_common_line)
print("出现次数:")
print(most_common_count)
posted @ 2023-07-04 09:47  yy9knsg  阅读(10)  评论(0编辑  收藏  举报