Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- const fs = require("fs");
- let data = fs.readFileSync(process.argv[3]).toString().split('\n');
- let n = false,
- m = false,
- i = false,
- count_m = 0;
- let string_to_find = process.argv[2],
- count = 0,
- pos = 0;
- for (let j = 2; j < process.argv.length; j++) {
- if (process.argv[j] == "-n")
- n = true;
- else if (process.argv[j] == '-i')
- i = true;
- else if (process.argv[j] == '-m') {
- m = true;
- count_m = process.argv[j + 1];
- }
- }
- if (i) {
- for (let i = 0; i < data.length; i++)
- data[i] = data[i].toLowerCase();
- string_to_find = string_to_find.toLowerCase();
- }
- if (m) {
- for (let i = 0; i < data.length; i++) {
- if (data[i] !== undefined)
- while ((pos = data[i].indexOf(string_to_find, pos + 1)) != -1)
- count++;
- if (count == count_m) {
- if (n)
- console.log(`${1+i} : ${data[i]}`);
- else
- console.log(data[i]);
- }
- count = 0;
- }
- } else {
- for (let i = 0; i < data.length; i++) {
- if (data[i] !== undefined && data[i].indexOf(string_to_find) > -1)
- if (n)
- console.log(`${1+i} : ${data[i]}`);
- else
- console.log(data[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement