Hi All,
1) I have requirement to save data to a textfile.
2)Then consequently perform a comparison for each line in the text file.
3) If there is line of word that exist on the file report
So far am able to read through the content and display on the console
But I dont know how to go about making the comparison.
Example: Given I ran my code the first time and saved on the textfile
Line #1'apple'
Line #2'mangoes'
Line #3'orange'
On the second > runs I want perform some kind of check or match
Say I am saving thesame :
Line #1'apple'
Line #2'mangoes'
Line #3'orange'
I want to be able to capture these matches.
***** Here is the code I have to read what was already in the file
Please any direction is greatly appreciated.
//***** create fs package
fs = require('fs');
readline = require('readline');
//const fs = require('fs');
//****** fileLoc to save pdf info
fileLoc ="C:/rawDeal.txt"
//********* ('\r\n') in input.txt as a single line break.
require('fs').readFileSync(fileLoc , 'utf-8').split(/\r?\n/).forEach(function(line){
console.log(line);
What I have tried:
fs = require('fs');
readline = require('readline');
fileLoc ="C:/rawDeal.txt"
require('fs').readFileSync(fileLoc , 'utf-8').split(/\r?\n/).forEach(function(line){
console.log(line);
******** Updated code that does not work*************************************.
const fileLines = fs.readFileSync(file, 'utf-8').split(/\r?\n/)
for(let index = 0; index < fileLines.length - 1; index++){
if(fileLines[index] === fileLines[index+1])
console.log("Matched lines are"+fileLines);
}else if(fileLines[index] !== fileLines[index+1])
console.log("Matched lines are"+fileLines);
console.log("No Matched lines found"+fileLines);
}