1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| import * as fs from 'fs'; import * as path from 'path'; import * as readline from 'readline';
const input_log_file_name = 'nohup20201107.out';
const input_file_path = path.join( __dirname, `../input files/${input_log_file_name}` ); const output_file_path = path.join( __dirname, `../output files/${input_log_file_name}` ); console.log(input_file_path);
async function processLineByLine() { const fileStream = fs.createReadStream(input_file_path);
const rl = readline.createInterface({ input: fileStream, crlfDelay: Infinity, });
const reg404 = /^.*(404).*/; let result_string = '';
for await (const line of rl) {
if (reg404.test(line)) { result_string += line + '\r\n'; } }
fs.writeFile(output_file_path, result_string, 'utf8', function (err) { if (err) throw err; console.log('file write complete'); }); }
processLineByLine();
|