Multi-File Extract: source file names in results list?

42 views
Skip to first unread message

Martin Post

unread,
Jan 20, 2021, 9:45:09 AM1/20/21
to BBEdit Talk
I need to build an (editable / exportable) list of terms from a Multi-File Search including the names of the files where the searched string / pattern is found. So my question is:

Is there a Replacement Pattern / token for the file name in a multi-file search, so clicking “Extract” in the Multi-File Search dialog would give me:

fil1.txt: foo.txt
file3.txt: fOO.txt
etc.

Thank you.

Bruce Van Allen

unread,
Jan 20, 2021, 10:25:51 AM1/20/21
to BBEdit Talk
Not sure the Multi-File search has a way to capture file names - but I
wouldn’t be surprised if someone points out how it can.

How’s your script-fu?

This could be done readily with a script (Perl, AppleScript, etc) or a
BBEdit text factory.

But clarify: your sample output looks like nothing but file names. Which
are the terms you mention searching for? I’m guessing the first item
before the colon is the file name.

Also:

1. Would there be only ONE term found per file?

2. ONE term pattern searched for at a time across all the files?

3. Will the files you’re searching all be in the same
directory/folder? That would affect how to write a script, and how
portable the operation is without tweaking each time.

Great question, and I’m sure folks on this list will have ideas.

HTH,

- Bruce

jj

unread,
Jan 20, 2021, 10:44:32 AM1/20/21
to BBEdit Talk
Hi Martin,

'File menu' > 'Export as text ...' usefully exports the results of a multi-file search.
Maybe that's something you could use.

HTH

Jean Jourdain

Martin Post

unread,
Jan 20, 2021, 2:34:51 PM1/20/21
to BBEdit Talk
@ Bruce:

Unfortunately, my script-fu is not worth mentioning. And yes, my source example was poorly formatted. I expect zero or more results for those searches, which should result in

file_1.txt: foo
file_1.txt: fOo
file_7.txt: fOO
etc. when searching for f(o)+

@ jj:

> File menu' > 'Export as text ...' usefully exports the results of a multi-file search.

I just tried saving a BBEDit multi-file search results window, but it doesn’t work: the file menu items are disabled, and the keyboard shortcuts don’t work, either.

*But* the content of said multi-file search results window can be selected and copied to the clipboard – and that’s fairly close to what I need: the file name and the full line with the match.

This allows me to drill down and extract file name and search terms in a second pass: 
Search for ^([^:]+):.*(foo)
Replace by \1\t\2

Not perfect, but close enough – so thank you for pointing me in the right direction. :)

Christopher Stone

unread,
Jan 21, 2021, 12:18:23 AM1/21/21
to BBEdit-Talk
On 01/20/2021, at 09:44, jj <goo...@mixio.com> wrote:
'File menu' > 'Export as text ...' usefully exports the results of a multi-file search.
Maybe that's something you could use.


Hey Folks,

You can also copy and paste them from the multi-file search results window.

-Chris

Christopher Stone

unread,
Jan 21, 2021, 12:40:36 AM1/21/21
to BBEdit-Talk
On 01/20/2021, at 13:34, Martin Post <martinpo...@gmail.com> wrote:
I just tried saving a BBEDit multi-file search results window, but it doesn’t work: the file menu items are disabled, and the keyboard shortcuts don’t work, either.


Hey Martin,

That's odd.  What version of BBEdit and macOS?

Export works fine for me with BBEdit 12.6.7 (412120) on macOS 10.12.6 Sierra and with BBEdit 13.5.x on macOS 10.14.6 Mojave.


Copy and paste work fine on both as well.

If this method works well enough for you I won't bother getting into the scripting of it.

--
Best Regards,
Chris

jj

unread,
Jan 21, 2021, 2:18:09 AM1/21/21
to BBEdit Talk

Hi Martin,

The 'Export as Text ...' menu item should be active if the Multi-File Search Results window is the front window and is not empty.

Best regards.

Jean Jourdain

Martin Post

unread,
Jan 21, 2021, 6:50:04 AM1/21/21
to BBEdit Talk
Hi Jean,

of course, you’re right. I was looking at / trying “Save (as)”. Tunnel vision. :| “Export as Text” works, as you say.

Thanks again!

Reply all
Reply to author
Forward
0 new messages