这个问题在这里已经有了答案:
解析文本文件中的独特单词 2个答案我想知道是否有方法在文本文件中查找(并显示)所有唯一的单词(出现一次的单词)? 这可以通过使用命令行来完成吗? 或者我会不得不使用类似python脚本的东西?
This question already has an answer here:
Parsing unique words from a text file 2 answersI was wondering if there is a way to find (and display) all the unique words (words that appear once) in a text file? Could this be done just using the command line? Or would I have to use something like a python script?
最满意答案
如果你不想编写应用程序,那么我可以想到的最简单的方法就是使用powershell。 看到这个:
https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/get-unique
Microsoft提供的示例使用唯一字词列表填充变量:
$A = $(foreach ($line in Get-Content C:\Test1\File1.txt) {$line.tolower().split(" ")}) | sort | Get-Unique您可能希望使用额外的分隔符来分隔标点符号,例如:
$A = $(foreach ($line in Get-Content C:\test.txt) {$line.tolower().split(" .,?!;:")}) | sort | Get-Unique把它放在一个扩展名为.ps1的文件中,你可以从命令行运行它。 为了从变量中获取数值,只需在变量的第二行将结果回显给屏幕:
$A要获得数组中项目的数量,您可以这样做:
$A.countIf you don't want to write an application then the easiest way that I can think to accomplish this is to use powershell. See this:
https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/get-unique
The example that Microsoft provides populates a variable with the list of unique words:
$A = $(foreach ($line in Get-Content C:\Test1\File1.txt) {$line.tolower().split(" ")}) | sort | Get-UniqueYou may wish you use additional delimiters though to split on punctuation such as this:
$A = $(foreach ($line in Get-Content C:\test.txt) {$line.tolower().split(" .,?!;:")}) | sort | Get-UniquePlace this in a file with the extension .ps1 and you can run it from the command line. In order to get the values out of the variable just a second line with the variable to echo the result to the screen:
$ATo get the count of items in the array you could do this:
$A.count更多推荐
发布评论