Find Files, Contents, Grep feature

Features wanted...
Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Find Files, Contents, Grep feature

Post by Stefan »

admin wrote:If your pattern is a*b then it would match "ab", "axb", "axxb", "axxxb" etc.
because wildcard * means "any number of characters".
In XY's content search, however, this "any number" is restricted.
The whole matching string "axxx.....b" will surely be found only if it is no longer than 1024 chars.
It *might* be found if it is no longer than 32,768 chars. I will not be found if it longer than 32,768 chars.
Question to be more clear:

1.) i imagine it like this:

Code: Select all

Searching [b]a*b[/b] on


"First chunk of 1024 chars [b]axxx..."
"...b[/b] Second chunk of 1024 chars"

will fail then OR It *might* be found.
Right?


2.)
Second question: what means *might* in this case for you? What are the conditions?

admin
Site Admin
Posts: 64875
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Find Files, Contents, Grep feature

Post by admin »

I read in chunks of 32,768 chars, and have them overlap by 1,024 chars.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Find Files, Contents, Grep feature

Post by Stefan »

admin wrote: If your pattern is a*b then it would match "ab", "axb", "axxb", "axxxb" etc. because wildcard * means "any number of characters".
In XY's content search, however, this "any number" is restricted.
The whole matching string "axxx.....b" will surely be found only if it is no longer than 1024 chars.
It *might* be found if it is no longer than 32,768 chars.
I will not be found if it longer than 32,768 chars.
admin wrote:I read in chunks of 32,768 chars, and have them overlap by 1,024 chars.


Understood. Thanks.

Code: Select all

|------------------------------------  file size -----------------------------------------|
xxxxxxxxx 32,768 chars  xxxxxxxxxxxx chunk 1
                        |1,024 chars| overlap
                        xxxxxxxxxxxxx 32,768 chars xxxxxxxxxxxxx chunk 2
                                                   |1,024 chars| overlap
                                                   xxxxxxxxxxxxx 32,768 chars xxxxxxxxxxxxx chunk ...

The RegEx search pattern (find string) 
"should be" less then 1024 chars to be able to match inside an chunk and even in the overlap between two chunks, 
but "could be" up to 32768 chars but with no chance to match this, if the string to match is spread over two chunks

admin
Site Admin
Posts: 64875
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Find Files, Contents, Grep feature

Post by admin »

Bingo! :)

Ash
Posts: 8
Joined: 24 Nov 2009 12:40

Re: Find Files, Contents, Grep feature

Post by Ash »

Don,

Thanks for the example and clarification, I understand now.

Most of my Regexp searches are in sourcecode files and are quite localised to smaller parts (eg. a single line) of the file so the 1024 wildcard limit should not be noticed.

It's good to have this discussion here so you can refer other users to this if they have similar questions.

Ash

dhrv
Posts: 14
Joined: 16 Dec 2011 18:23

Re: Find Files, Contents, Grep feature

Post by dhrv »

When finding content in files, is it possible to display a column that shows the matched part and the context around it, similar to "grep -B5 -A5 mystring dir/"? There are standalone tools for Windows that can do this (grepWin, dnGrep) but it would be helpful to have this feature in XYplorer.

highend
Posts: 14570
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Find Files, Contents, Grep feature

Post by highend »

I don't think that this makes much sense (at least when it comes to linebreaks) but you could try to write a custom column script for this.

E.g.:

Code: Select all

$content = get("find_contents");
gets you the content of the "Contents" field from the last search

Have fun building the necessary regexes for the cc script, though...
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 64875
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Find Files, Contents, Grep feature

Post by admin »

dhrv wrote:When finding content in files, is it possible to display a column that shows the matched part and the context around it, similar to "grep -B5 -A5 mystring dir/"? There are standalone tools for Windows that can do this (grepWin, dnGrep) but it would be helpful to have this feature in XYplorer.
It would be a useful thing. I'll think about it.

dhrv
Posts: 14
Joined: 16 Dec 2011 18:23

Re: Find Files, Contents, Grep feature

Post by dhrv »

Thanks for the quick replies. Hehe yeah, you're right, I even struggle to extract the first match properly (btw, is it possible to apply basic formatting like bold or italics to parts of the text of the custom column?). If I'm successful, I will post the script here, if not, I let Donald surprise me :D

highend
Posts: 14570
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Find Files, Contents, Grep feature

Post by highend »

How do you want to display multiple /r/n or /n separated lines of "surrounding text lines" in a single line column so that it makes sense for the user?

Apart from that, regexmatching isn't hard but you shouldn't forget that this could produce many lines depending on how often the search text is found...

Code: Select all

    $stringToFind = "word";

    $string = <<<>>>
1st line
2nd line
3rd line
4th line
a word to find
6th line
7th line
8th line
9th line
>>>;
    // Incl. two lines before
    text "Before: <crlf>" . regexmatches($string, "(^.*\r?\n){2}.*?" . $stringToFind, <crlf>);
    // Incl. three lines after
    text "After: <crlf>" . regexmatches($string, $stringToFind . "(.*\r?\n){4}", <crlf>);
btw, is it possible to apply basic formatting like bold or italics to parts of the text of the custom column?
Nope, not atm...
One of my scripts helped you out? Please donate via Paypal

Post Reply