Created
February 14, 2017 13:51
-
-
Save dimm999/7d7e1d36d665dd0789f0e5e3a05684b6 to your computer and use it in GitHub Desktop.
nodejs read all files in dir and replace some part of string inside
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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