Skip to content

Instantly share code, notes, and snippets.

@jthatch
Created December 13, 2016 16:27
Show Gist options
  • Save jthatch/f1bbd49d572dfef5345b505acc4f009d to your computer and use it in GitHub Desktop.
Save jthatch/f1bbd49d572dfef5345b505acc4f009d to your computer and use it in GitHub Desktop.
Strip mIRC color codes and tags from log files
#!/usr/bin/env node
/*
* stripmirc.js
* strip mirc color codes from logs
*
* Examples:
*
* ./stripmirc.js irc-log.txt > irc-log-new.txt
*
* (c) jthatch http://github.com/jthatch
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
'use strict';
const fs = require('fs');
const util = require('util');
const path = require('path');
function Strip() {
this.logFile = process.argv[2] || false;
}
Strip.prototype.init = function() {
if (!this.logFile) {
this.usage();
process.exit();
}
this.strip();
};
/**
* reads a log file into a string
* @return string log
*/
Strip.prototype.strip = function() {
try {
var log = fs.readFileSync(this.logFile).toString('utf8');
log.replace(/\x03(?:\d{1,2}(?:,\d{1,2})?)?/g, '');
console.log(log);
}
catch (e) {
console.log(" " + e);
return false;
}
};
/**
* Show usage
*/
Strip.prototype.usage = function() {
console.log("\n" + " Usage: " + path.parse(__filename).base + " [logfile]" + "\n");
};
var strip = new Strip();
strip.init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment