Find in Files - Match if String Not Found problem

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

Find in Files - Match if String Not Found problem

Postby Casey.Robertson » Tue Jul 31, 2007 9:28 pm

New to the software so bear with. I have a project where I am parsing a large number of .ini files. If these files DO NOT contain specific text I want to insert a block of text - i.e. if the file does not contain a section called [Print Default].

I have figured out how to find the files that do not contain the text using the "Match files if string is not found" operator. I can also run a text replacement easily enough.

The trouble is that I can't figure out a clean way to open/pass the files that DO NOT contain this text to the replacement operation so that they can be the target of my replacement. I can output the files out find to the editor window but is there a way to tell it to Open the files that are found?

Help! This will save me an awful lot of time if I can figure it out.

Thanks in advance!

Casey Robertson

Version 13.10a+1 UltraEdit Style Regular expressions
User avatar
Casey.Robertson
Newbie
 
Posts: 2
Joined: Mon Jul 30, 2007 11:00 pm

Re: Find in Files - Match if String Not Found problem

Postby Mofi » Wed Aug 01, 2007 6:55 am

Run your Find In Files with option Results to Edit Window checked.

Assuming you have not changed the options for the Find In Files output format following macro can then be executed on this output to open all the files.

Macro to open all files not containing a string:

InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Find MatchCase "Search complete,"
IfFound
DeleteLine
UnicodeToASCII
Top
Find "----------------------------------------^p"
Replace All ""
Find MatchCase RegExp "Search for files that do not contain *^p"
Replace All ""
Loop
IfEof
ExitLoop
EndIf
StartSelect
Key END
Open "^s"
NextWindow
DeleteLine
EndLoop
CloseFile NoSave
EndIf

The macro property Continue if a Find with Replace not found must be checked for this macro.

Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.

Now you can run your replace on all open files.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Find in Files - Match if String Not Found problem

Postby Casey.Robertson » Wed Aug 01, 2007 3:06 pm

That worked perfectly! You have no idea how much time you saved me from having to figure that out. Thanks again!

BTW, I was in Austria a couple of years ago - what a beautiful country!

--Casey
User avatar
Casey.Robertson
Newbie
 
Posts: 2
Joined: Mon Jul 30, 2007 11:00 pm


Return to Find/Replace/Regular Expressions