Skip to content

Instantly share code, notes, and snippets.

@dimawebmaker
Created February 14, 2017 13:51
Show Gist options
  • Save dimawebmaker/7d7e1d36d665dd0789f0e5e3a05684b6 to your computer and use it in GitHub Desktop.
Save dimawebmaker/7d7e1d36d665dd0789f0e5e3a05684b6 to your computer and use it in GitHub Desktop.
nodejs read all files in dir and replace some part of string inside
const cfgFolder = './cfg/';
const fs = require('fs');
const outFile = './out.txt';
fs.readdir(cfgFolder, (err, files) => {
files.forEach(file => {
fs.readFile(cfgFolder+file, 'utf8', (err, data) => {
if(err) throw err;
let pass = data.match(/(blabla.+)/i);
pass = pass[0].trim();
let ip = data.match(/blabla(.+) /i);
ip = ip[1].trim();
ip = ip.replace('254', '253');
fs.appendFile(outFile, `${ip} ${pass} \n`, (err)=>{
console.log(err);
})
});
});
})
//iproute default(.+)
//(bgtyhn.+)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment