我有一个这样的txt文件:
ksakks ...... ......
ksakks ...... ......
ksakks ...... ......
ksakks ...... ......
ksakks ...... ......
ksakks ...... ......
bccscd ...... ......
bccscd ...... ......
bccscd ...... ......
bccscd ...... ......
...
我要数线。例如:
ksakks
有6行,bccscd
只有4行。如果其中一些少于3行,则我必须保存其“名称”,如果有更多行,则必须将其“名称”保存在数组中。我怎样才能做到这一点?
最佳答案
您可以使用Select-Sting
提取文本,然后使用Group-Object
进行计数。像这样:
(Select-String .\yourfile.txt -Pattern '^.{6}' ).Matches | Select -ExpandProperty value | Group-Object | Select Name, Count
关于arrays - 如果仅前6个字符不同,如何计算行数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41074669/