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

159
Vistas
Removing "," at the beginning of a line CSV

i want to convert a .csv file and write a new one. However I am not able to remove the first , i am kinda stuck here and it is driving me crazy. This is my code:

    var extractedtasks = tasks.slice(0, 3)
    var extractedtasksformated = extractedtasks.toString().replace(/,$/g, "\n")

    let csvformat = "EMAIL,PASSWORD,MAILBOX"
    fs.writeFileSync(tasklocation[0], csvformat + "\n" + extractedtasksformated.replace(/,^/g, 
    ""))
    console.log(chalk.green("Successfully updated the CSV file"))

That's the output i am getting in the newly generated file

EMAIL,PASSWORD,MAILBOX
example1@gmail.com,Password123,example@gmail.com:password
,example2@gmail.com,Password123,example@gmail.com:password
,example3@gmail.com,Password123,example@gmail.com:password

Output extractedtasks:

[
  'example1@gmail.com,Password123,example@gmail.com:password\r',
  'example2@gmail.com,Password123,example@gmail.com:password\r',
  'example3@gmail.com,Password123,example@gmail.com:password\r'
]

Output extractedtasksformated:

,example3@gmail.com,Password123,example@gmail.com:passwordxample@gmail.com:password
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Because extractedtasks is an array, instead of converting it to a string you should just join it with the expected separator:

extractedtasks = [
  'example1@gmail.com,Password123,example@gmail.com:password\r',
  'example2@gmail.com,Password123,example@gmail.com:password\r',
  'example3@gmail.com,Password123,example@gmail.com:password\r'
]

extractedtasksJoined = extractedtasks.join("\n")
// "example1@gmail.com,Password123,example@gmail.com:password\r\nexample2@gmail.com..."

// depending on the target line separator, you should also probably
// remove the "\r"
extractedtasksJoined = extractedtasksJoined.replace("\r", "")

// finally
fs.writeFileSync(tasklocation[0], csvformat + "\n" + extractedtasksJoined + "\n")
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