Sunday, 4 June 2017

Output all text after common string to new file in Node

I'm trying to create a program that writes all text after a string to a new text file using node. So far I've been able to search the document for the common string, but I'm stuck on how to write only the text after it. I might be going about this problem in the wrong way, but any help would be greatly appreciated! This is where I am:

var fs = require('fs');

var readableStream = fs.createReadStream('main.txt');
var writableStream = fs.createWriteStream('output.txt');

var search = '/****************** Version 2 **********************/';

var body = fs.readFileSync('main.txt').toString();

if (body.indexOf(search) > 0) {
    console.log('FOUND');
} else {
    console.log('not found');
}



via SubspaceNightmare

No comments:

Post a Comment