-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCanFilter.js
More file actions
50 lines (38 loc) · 1.69 KB
/
CanFilter.js
File metadata and controls
50 lines (38 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const process = require('process');
const fs = require('fs');
// CAN Filter
function exec() {
let fileName = process.argv[2] || '';
if (fileName == '') return console.log('Please select file');
console.log('Open file', process.argv[2]);
fs.readFile(fileName, 'utf8', function(err, contents) {
if (err) return console.error(err);
let arr = [], idListCount = {}, unicSetId = new Set();
arr = contents.split('\n');
for (let i = 0; i < arr.length; i++) {
if (arr[i].split('8').length == 2){
let id = arr[i].split(' ')[1];
let data = arr[i].split('8')[1];
if (idListCount[id] === undefined) idListCount[id] = data;
else if (idListCount[id] !== data) unicSetId.add(id);
}
}
let unicArr = [...unicSetId];
for (let i = 0; i < unicArr.length; i++) {
const el = unicArr[i];
let currID = arr.filter(v=>el == v.split(' ')[1] );
console.log(el, currID.length);
let idFile = currID.join('\n');
let fileNameId = fileName.split('.')[0]+'_'+el+'.txt';
fs.writeFile(fileNameId, idFile, (err) => {if (err) throw err;} );
}
let filteredId = arr.filter(v=>unicSetId.has( v.split(' ')[1]) );
let unFilteredId = arr.filter(v=>!unicSetId.has( v.split(' ')[1]) );
fs.writeFile(fileName.split('.')[0]+'_fixed.txt',
unFilteredId.join('\n'), (err) => {if (err) throw err;} );
console.log('Total row' ,arr.length, 'Filtered' ,
filteredId.length,'Fixed ID' , unFilteredId.length,
'Changed ID' , unicSetId.size);
});
}
exec();