kaesetoast / find-in-files Goto Github PK
View Code? Open in Web Editor NEWA simple tool to search text patterns across multiple files
License: MIT License
A simple tool to search text patterns across multiple files
License: MIT License
when i try to use this library for pdf files its not working
An ignore pattern would be extremely handy...
error is thrown when I ignore regex, or put simple regex like '.js$'. Why it doesn't work?
findInFiles.find("xxx", 'xxxx', '.js$')
.then(function(results) {
for (var result in results) {
var res = results[result];
console.log(
'found "' + res.matches[0] + '" ' + res.count
+ ' times in "' + result + '"'
);
}
});
`/Users/msu/test/node_modules/q/q.js:155
throw e;
^
TypeError: Cannot read property 'match' of undefined
at getResults (/Users/msu/test/node_modules/find-in-files/index.js:74:22)
at /Users/msu/test/node_modules/find-in-files/index.js:92:30`
Hi, thank you for this great package.
Would it be possible to end a search as soon as the string is found once? I am comparing a list of strings to a list of files, and I have no need to know if the string is found more than the first hit.
Thank you
I check the all file format to search the file but it not support latest file format like docx,xlsx,pptx and pdf.
If any solution,let me know.
Nice module!
is it possible to add line numbers to the results?
I'm trying to write a script where you pass a full path to a file and it will search it but when i run the search I get
{ Error: ENOENT: no such file or directory, lstat '/Users/username/Development/internal/test.html '
errno: -2,
code: 'ENOENT',
syscall: 'lstat',
path: '/Users/username/Development/internal/test.html ' }
Can I find a file using the full path or does it need to be in the same directory as the script?
Hi all, I kindly ask for a support. I need to search in mid-size text files (one at the time, 50/60 MB size) for regexp that search for 2 strings one "near" the other.
The use case is to automatically search for patterns (request/answer) in log files.
Example:
text file fragment
000000: USB-SERIAL CH340 (COM12), 2018-11-26 17:35:54,3748068
0A 03 00 00 00 17 04 BF .......¿
000001: USB-SERIAL CH340 (COM10), 2018-11-26 17:35:54,9676068 +0,5928000
0A 03 2E 00 01 00 00 00 18 00 18 00 19 00 18 00 ................
19 00 31 00 01 00 01 00 01 00 01 01 CC 70 DE C3 ..1.........ÌpÞÃ
4F 95 02 00 00 00 00 00 00 00 00 00 00 00 00 0C O•..............
B7 E5 45 ·åE
First i search for the request pattern using theexample code with this "regexp" and i find the expected result:
findInFiles.find({'term': "0A 03 00 00 00 17 04 BF", 'flags': 'gm'}, '.', '.txt$')
found "0A 03 00 00 00 17 04 BF" 752 times in "181127_0944_ReqView.txt"
Then i search for the req/ans pattern where the result involve search in multiple lines and it finds nothing:
findInFiles.find({'term': "0A 03 00 00 00 17 04 BF\W+(?:\w+\W+){1,40}? 0A 03 2E", 'flags': 'gm'}, '.', '.txt$')
Using the same regexp in notepad++ search returns the expected results:
Can someone kindly give me an hint (i'm not an expert programmer i'm writing just few lines of code to automate field tests) ?
Thanks a lot
Look at the function getResults
starting on line 69 and how the results
array is used as a key-value data structure:
function getResults(content) {
var results = []
for (var i = 0; i < content.length; i++) {
var fileMatch = content[i].value;
if (fileMatch.match !== null) {
results[fileMatch.filename] = {
matches: fileMatch.match,
count: fileMatch.match.length,
line: fileMatch.lines
};
}
}
return results;
}
Although being valid JavaScript, this seems quite unconventional and leads to weird behaviour. For example, results.length
equals zero. Is this a programming error? If the author intended to preserve the order, this is not the way how to do it. Arrays are objects and the order of the keys of an object is unspecified.
I guess there are two solutions. The first is simply var results = {}
. The second option would be to still use an array but instead push objects into it, with additional key filename
:
results.push({
filename: fileMatch.filename,
matches: fileMatch.match,
count: fileMatch.match.length,
line: fileMatch.lines
});
Thanks a lot for the amazing package!
I am trying to use it to search logs files throw my project.
I am getting this error in the Node console
<--- Last few GCs --->
[17904:0000014A7121EE00] 13909 ms: Scavenge 1960.9 (2056.5) -> 1959.1 (2071.5) MB, 23.8 / 0.0 ms (average mu = 0.866, current mu = 0.628) allocation failure
[17904:0000014A7121EE00] 14304 ms: Mark-sweep 1974.0 (2071.5) -> 1972.1 (2087.5) MB, 374.3 / 0.0 ms (average mu = 0.726, current mu = 0.367) allocation failure scavenge might not succeed
<--- JS stacktrace --->
FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory
1: 00007FF793E1058F napi_wrap+109311
I understand it is a memory issue..
there is any workaround for it?
currently there are 10 folders in the root. and each of them contain 2 more logs file.
Each of the logs files contain 5 line of text
Thanks a lot!
It'd be nice to have glob support for file matching. Because when I set a folder which contains a node_modules
... 😅
i want find string from start of each line not between them.
Hello,
I want to search multiple string values in a file using your library. Is that possible ?
findInFiles.find({'term': "str1 | str2 | str3" , 'flags': 'ig'}, '.', '.txt$')
.then(function(results) {
for (var result in results) {
var res = results[result];
console.log(
'found "' + res.matches[0] + '" ' + res.count
+ ' times in "' + result + '"'
);
}
});
The return value is not an Object but it's an Array
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.