Find multiple strings with one search and output them to a file

Find, replace, find in files, replace in files, regular expressions

Find multiple strings with one search and output them to a file

Postby kapaoke » Wed Sep 16, 2009 6:09 pm

Hi,

I tried to search forum for this but had a hard time to find what I was looking for.
If anyone could point me to some existing post on this forum, it would be great.
I am trying to find a way to search for multiple strings of data at the same time, for example DATETIME, SYNTAX, DECLARE, in q file with more then 1 million rows and if possible extract those lines which contain one of those strings to a file with a line number.

Thanks
kapaoke
Newbie
 
Posts: 1
Joined: Wed Sep 16, 2009 6:00 pm

Re: Find multiple strings with one search and output them to a file

Postby Mofi » Thu Sep 17, 2009 12:48 am

If you need this only once, do following after opening the file:

  • Press Ctrl+F to open the Find dialog.
  • Enter in Find What the string word 1|string 2|word3|string4 .
  • Check the option Match Case if it is not important to search not case sensitive. A case sensitive search is faster than a search ignoring the case of letters.
  • Check the option Regular Expressions which is required for this search because | is a Perl regular expression character which means OR.
  • Click on button Advanced if you do not already see the advanced options.
  • Select the regular expression engine Perl which is the only regexp engine supporting more than 2 arguments in an OR expression.
  • Check the option List Lines Containing String.
  • Find Where should be set to Current File and the other 3 options should not be enabled.
  • Run the search now with pressing button Next.
    A dialog opens showing you the lines with one of the words / strings you entered.
  • If you don't see the line numbers in this dialog, check the option Show Line Numbers in the bottom right corner of the dialog.
  • Press the button Clipboard to copy what you see in the dialog to the clipboard and close the dialog with a click on button Close.
  • Press Ctrl+N to open a new file and press Ctrl+V to paste into the new file the just copied lines with the line number.
That's it. If you need this often, it would be better to do the same with a script or a macro. There are already some macros and scripts for the List Lines Containing String feature in the macro and script forums.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Find multiple strings with one search and output them to a file

Postby coder03 » Mon Sep 28, 2009 12:32 pm

I have a somewhat similar problem that I am having difficulty with. I have an environment where I'm regularly trying to locate all source members of a project (over 1,900 members) of a given set of strings. for instance... $810blah|$910blah|$verblah I have tried using the Find In Files, setting to regular expression search (perl engine) and putting the string exactly as shown above. I yeild no results. although I know there are many but need to get an exhaustive listing of them. I have tried unsuccessfully many different types but have come up empty. Can you give me a boost on this? Thanks -- Paul
coder03
Newbie
 
Posts: 3
Joined: Fri Sep 18, 2009 8:07 am

Re: Find multiple strings with one search and output them to a file

Postby Mofi » Tue Sep 29, 2009 12:01 am

The character $ has a special meaning when running a regular expression search, see in help of UltraEdit the page Regular Expressions (Perl Style). It means end of line. So you have to put the escape character \ left to every $ to force the engine to interpret the character $ as character $ and not as end of line anchor. Your search string must be therefore \$810blah|\$910blah|\$verblah
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Find multiple strings with one search and output them to a file

Postby coder03 » Wed Sep 30, 2009 2:25 pm

Thanks! :)
coder03
Newbie
 
Posts: 3
Joined: Fri Sep 18, 2009 8:07 am


Return to Find/Replace/Regular Expressions