[英]How can I check for repeating lines in a text file with node.js?
I am creating a node.js program which scans through a log file and outputs information from it to a console.我正在创建一个 node.js 程序,它扫描日志文件并将信息从它输出到控制台。
Sometimes, the log file can contain errors which can repeat basically forever (I'm talking like 20000 times).有时,日志文件可能包含基本上可以永远重复的错误(我说的是 20000 次)。
I need a way to check if any portion of text is repeated multiple times in the file.我需要一种方法来检查文件中是否有任何文本部分重复多次。
Since I don't know what text I'm looking for, I can't use native JS functions, regex, or stuff like that.因为我不知道我在寻找什么文本,所以我不能使用原生 JS 函数、正则表达式或类似的东西。
Does anyone know how I could achieve this without using machine learning?有谁知道我如何在不使用机器学习的情况下实现这一目标?
I have not tried anything yet because I have absolutely no clue how this could be achieved.我还没有尝试过任何东西,因为我完全不知道如何实现这一点。
Break the problem up into multiple steps.将问题分解为多个步骤。 Deal with one step at a time.
一次处理一个步骤。 So, for step one, your task is to figure out how to read a file from disk into a variable.
因此,对于第一步,您的任务是弄清楚如何将文件从磁盘读取到变量中。 Next step: turn that variable into an array.
下一步:将该变量转换为数组。 etc.
等等。
You can use an algorithm something like this:你可以使用这样的算法:
At the end, you will have an output array consisting only of unique log entries.最后,您将拥有一个仅包含唯一日志条目的输出数组。 Write it out to a file.
将其写入文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.