//从文件中提取文件指从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;