Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda