Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to skip first lines of the file with node-csv parser?

Tags:

node.js

csv

Currently I'm using node-csv (http://www.adaltas.com/projects/node-csv/) for csv file parsing.

Is there a way to skip first few lines of the file before starting to parse the data? As some csv reports for example have report details in the first few lines before the actual headers and data start.

LOG REPORT                  <- data about the report
DATE: 1.1.1900
DATE,EVENT,MESSAGE          <- data headers
1.1.1900,LOG,Hello World!   <- actual data stars here
like image 446
crappish Avatar asked Jan 10 '14 09:01

crappish


1 Answers

All you need to do to pass argument {from_line: 2}inside parse() function. like the snippet below

const fs = require('fs');
const parse = require('csv-parse');

fs.createReadStream('path/to/file')
    .pipe(parse({ delimiter: ',', from_line: 2 }))
    .on('data', (row) => {
        // it will start from 2nd row
        console.log(row)
    })
like image 156
Raad Altaie Avatar answered Oct 14 '22 06:10

Raad Altaie