使用Node-ETL

时间:2016-07-23 03:03:36

标签: javascript node.js etl business-intelligence node-etl

使用node-etl,如果有一个空格分隔符,我可以将文件内容提取到JS数组中:

data.txt

21 Ahmed UK
54 Jean Chine
65 Mourad Tunisia

load.js

var ETL=require('node-etl')
var people=ETL.extract('./data.txt',{
      delimitor:" ", //just ONE Space . What about ONE or many spaces
      headers:["id","name","country"],
 });
 /*
    [
           {id:"21",name:"Ahmed",country:"UK"}, 
           {id:"54",name:"Jean",country:"Chine"},
           {id:"65",name:"Mourad",country:"Tunisia"},      


       ]

 */

现在,如果数据之间的空间不固定(一个或多个)怎么办?什么是合适的分隔符?

data.txt

21 Ahmed                  UK
54                Jean Chine
65        Mourad     Tunisia

1 个答案:

答案 0 :(得分:0)

实测!

Node-ETL包提供了一些现成的静态分隔符,对于这种情况,ETL.DLM_SPACE_OR_MORE是合适的。

然后,代码应为:

var people=ETL.extract('./data.txt',{
      delimitor:ETL.DLM_SPACE_OR_MORE, //just ONE Space . What about ONE or many spaces
      headers:["id","name","country"],
 });
 /*