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