Skip to content

Instantly share code, notes, and snippets.

@karan9
Last active December 1, 2020 19:43
Show Gist options
  • Save karan9/c8d5bf7f6f50b352066bc9151e7e0b5d to your computer and use it in GitHub Desktop.
Save karan9/c8d5bf7f6f50b352066bc9151e7e0b5d to your computer and use it in GitHub Desktop.
Simple MongoDB Log Fixer For People who use windowwwwzzzz
const rl = require("readline");
const FILEPATH = "/Users/Karan.Srivastava/Desktop/Manish Sahni/s1.log";
const OUTPUTFILE = "s1k.log";
const lineReader = rl.createInterface({
input: require("fs").createReadStream(require("path").normalize(FILEPATH))
})
let prevLine = "";
lineReader.on("line", (line) => {
if (line.startsWith("2020") && prevLine) {
require("fs").appendFileSync(OUTPUTFILE, prevLine + require("os").EOL, { encoding: "utf-8" })
prevLine = "";
prevLine = line;
} else {
prevLine += line
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment