码迷,mamicode.com
首页 > Web开发 > 详细

nodejs对文件进行分页

时间:2015-07-09 17:35:07      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

//从文件中提取文件指从x行到y行的内容 
//awk -v start=5 -v end=10 -F "\x01" ‘{if(NR>=start && NR<=end)print $1,NR}‘ app_v2.csv var exec = require(‘child_process‘).exec; var fs = require(‘fs‘); var shell = {}; shell.getContentFromFile = function(file, pageIndex, pageSize, split, next) { fs.exists(file, function(exists) { if (!exists) { next(‘file not exist‘+file, null, null); } var start = (pageIndex - 1) * pageSize + 1; var end = (pageIndex) * pageSize; var cmd = "gzip -d -c " + file + " | awk -v start=" + start + " -v end=" + end + " -F " + split + " ‘{ if(NR>=start && NR<=end) print $0}‘ "; console.log(" the awk: " + cmd); exec(cmd, function(err, stdout, stderr) { if (err) { console.log(err); } next(err, stdout, stderr); }); }); }; shell.getFileLineCount = function(file, next) { fs.exists(file, function(exists) { if (!exists) { next(‘file not exist‘+file, null, null); } var cmd = "gzip -d -c " + file + " | cat | wc -l"; exec(cmd, next); }); }; module.exports = shell;

 

nodejs对文件进行分页

标签:

原文地址:http://www.cnblogs.com/witwave/p/4633629.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!