Windows PowerShell 查找文件中的重复行 [英] Windows PowerShell to find duplicate lines in a file

查看:54
本文介绍了Windows PowerShell 查找文件中的重复行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 Power Shell 在文本文件中查找重复值假设文件内容是

I need to find the duplicate values in a text file using power shell let's say if the file content is

Apple
Orange
Banana
Orange
Orange

期望的输出应该是

Orange
Orange

推荐答案

您还可以使用 Group-Object cmdlet 查看是否有任何行出现多次:

You can also use the Group-Object cmdlet to see if any lines occur more than once:

例如

Get-Content test.txt | Group-Object | Where-Object { $_.Count -gt 1 } | Select -ExpandProperty Name

这篇关于Windows PowerShell 查找文件中的重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆