Find all instances and copy to new document

761 views
Skip to first unread message

jw123

unread,
Jun 24, 2014, 11:00:41 AM6/24/14
to textwr...@googlegroups.com
In TextWrangler, is there any way to search for a regular expression, and then copy a list of all the matches into a new file? For example, I might want to find all URLs in a document, and then work with just the URLs. I can create a regex to find them, but how can I get a list of all the results?

If not, this would be a very useful feature to have. You could add a "Copy to new document" checkbox to the Find dialog. Maybe it could even work with Replace, so you could copy the replaced text instead of the found text. For example, you might want to find all URLs, but just get a list of the host names. So you could replace the expression with a matched subexpression, and copy those to a new document.

JW

Thomas Fischer

unread,
Jun 24, 2014, 11:45:45 AM6/24/14
to textwr...@googlegroups.com
Hello,

in TextWranger there is under
Text -> Process Lines…
the option to bach process lines (erase, copy,…).
You can also use regular expressions here.
This will work if you're dealing with a single file.

If you want to find matches in different files, you can use the Multi-File Search and select all the matches (the top part of the window) and copy them to a new document, this will give you entries like
<file path>:<line number>:<line matched>
(I would probably rather use the unix grep function for that, though.)

Hope this helps, best
Thomas

--
This is the TextWrangler Talk public discussion group.
If you have a feature request or would like to report a problem,
please email "sup...@barebones.com" instead of posting here.
---
You received this message because you are subscribed to the Google Groups "TextWrangler Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to textwrangler...@googlegroups.com.

jw123

unread,
Jul 7, 2014, 12:13:48 PM7/7/14
to textwr...@googlegroups.com
True, but both of those will only give you the line containing the match, not the match itself. So you still have to do a second manual step, to find the matches within each line.

JW

Tony Chung

unread,
Jul 7, 2014, 1:43:46 PM7/7/14
to textwr...@googlegroups.com
That would definitely save the second step. Multi-document search only shows the matches. You could probably write an AppleScript to perform single or multi document searches and collect the matches into a new document.

-Tony
Reply all
Reply to author
Forward
0 new messages