const fs = require('fs');
const path = require('path');
/**
* Strips metadata from a log file.
* @param {string} inputFilePath Path to the input log file.
* @param {string} outputFilePath Path to the output log file (without metadata).
*/
function stripMetadata(inputFilePath, outputFilePath) {
fs.readFile(inputFilePath, 'utf8', (err, data) => {
if (err) {
console.error(`Error reading file: ${err}`);
return;
}
// Simple metadata removal: removes lines starting with common metadata indicators.
const metadataIndicators = ['#', 'Date:', 'Time:', 'Source:'];
const lines = data.split('\n');
const cleanedLines = lines.filter(line => !metadataIndicators.some(indicator => line.startsWith(indicator)));
const cleanedData = cleanedLines.join('\n');
fs.writeFile(outputFilePath, cleanedData, 'utf8', (err) => {
if (err) {
console.error(`Error writing to file: ${err}`);
return;
}
console.log(`Metadata stripped from ${inputFilePath} and saved to ${outputFilePath}`);
});
});
}
//Example usage:
// stripMetadata('input.log', 'output.log');
Add your comment