Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
Get line of file content that contain a string

I wanted to get line content in a file that contains a string in discord js node.

Something like this:

If (file contains("string")){
console.log(line content)
}

like, if one of the lines in the file contains the string. It's gonna send the line that contains the string to the console.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

So all you need is to split the file content by new line and iterate over the lines to find the date like so:

const testFolder = './logs/Chatlogs';
const fs = require('fs');
const path = require('path');

fs.readdirSync(testFolder).forEach(file => {
    console.log(file);

    // read the file content
    var content = fs.readFileSync(path.join(testFolder, file));

    var date = '20211203';
    var lines = content.split('\n');

    lines.forEach(l => {
        if(l.indexOf(date) > -1)
            console.log('Found it:', l);
    });
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!