首页 > Web开发 > 详细

nodejs对文件进行分页

时间:2015-07-09 17:33:05      阅读:229      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!