Created
April 19, 2014 07:20
-
-
Save chengmu/11076719 to your computer and use it in GitHub Desktop.
用于删除译稿中英文的脚本
This file contains hidden or 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
/** | |
* 用于删除翻译完的稿子中英文部分的脚本 | |
*/ | |
var resultFileName = 'r.txt'; | |
var inputFileName = 'raw.txt'; | |
var fs = require('fs'); | |
function readLines(input, func) { | |
var remaining = ''; | |
input.on('data', function(data) { | |
remaining += data; | |
var index = remaining.indexOf('\n'); | |
while (index > -1) { | |
var line = remaining.substring(0, index); | |
remaining = remaining.substring(index + 1); | |
func(line); | |
index = remaining.indexOf('\n'); | |
} | |
}); | |
input.on('end', function() { | |
if (remaining.length > 0) { | |
func(remaining); | |
} | |
}); | |
} | |
var result = []; | |
function func(data) { | |
if (!/.*[a-z|A-Z]+.*/.test(data)) { | |
result.push(data); | |
fs.writeFile(inputFileName, result.join('\n'), 'UTF-8', function (err) { | |
if(err) {console.log(err);} | |
}); | |
} | |
} | |
var input = fs.createReadStream(resultFileName); | |
readLines(input, func); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment