dsh-sansheng-liubu/preview/dump-grep.mjs

8 lines
330 B
JavaScript

import fs from 'node:fs'
const text = fs.readFileSync(process.argv[2], 'utf8')
console.log('LEN', text.length)
for (const key of process.argv.slice(3)) {
let i = -1, n = 0
while ((i = text.indexOf(key, i + 1)) >= 0 && n < 2) { console.log('\n### ' + key + ' @' + i); console.log(text.slice(Math.max(0,i-200), i+260)); n++ }
}