Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a node.js code that will read the log.txt. I have the simple code that is reading the file, but I want to find the occurrence of the text and show me the number of occurrences for each text.

log.text : 02/04/2020|abc,02/04/2020|123,02/04/2020|123,02/04/2020|bcd,02/04/2020|123,02/04/2020|abc

Output :

abc : 2
123 : 3
bcd : 1

CODE:

 // Read the file and print its contents.
    var fs = require('fs')
      , filename = process.argv[2];
    fs.readFile(filename, 'utf8', function(err, data) {
      if (err) throw err;
      console.log('OK: ' + filename);
      console.log(data)
    });
question from:https://stackoverflow.com/questions/66052334/node-js-read-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
199 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...