I have a file which consists of places where there are multiple underscores. I need to convert them all to single underscores.
How can I do this in Node?
My current solution:
var fs = require("fs");
filename = "questions.txt";
ofilename = "o.txt";
fs.readFile(filename, "utf8", function (err, data) {
if (err) {
return console.log(err);
}
var result = data.replace(/_+/g, "_");
fs.writeFile(ofilename, result, "utf8", function (err) {
if (err) return console.log(err);
});
});
This gives me a file where everything is in binary.
sedin terminalsed 's/__*/_/g' questions.txt> o.txtto save to a filesed 's/__*/_/g' test.txt > o.txt-ito modify filesed -i 's/__*/_/g' test.txt