Grep: find files in directory4string & log filename to file

Help with writing and playing macros

Grep: find files in directory4string & log filename to file

Postby ecpro » Thu Nov 09, 2006 2:54 pm

Hi I'm trying to search a directory for files containing a specific string and log the path and filename that contain the search string to a new file. I'm trying to mimic the grep command in unix. Hope someone can help me.

Thanks Val
User avatar
ecpro
Newbie
 
Posts: 1
Joined: Thu Nov 09, 2006 12:00 am

Re: Grep: find files in directory 4 string & log filenames

Postby Mofi » Thu Nov 09, 2006 3:28 pm

This thread is maybe helpful for you: equivalent to egrep ?? (extract line from big files)

And here is a macro which uses FindInFiles to create a list of files in which the search string is found.

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

It contains some extra code which are workarounds for known problems with Find In Files usage in a macro and should work for v10.20 and higher (tested with v11.20a and v12.20a+1). Since v12.00 the search result is a Unicode file which is detected by this macro and converted to an ASCII file to avoid some problems with Unicode files.

Adapt the optional and required parameters of command FindInFiles to your need.

InsertMode
ColumnModeOff
HexOff
UnixReOff
FindInFiles Recursive "Initial directory\" "file specification" "search string"
Loop
Find RegExp Up "%Search complete, found"
IfNotFound
NextWindow
Else
DeleteLine
ExitLoop
EndIf
EndLoop
Top
HexOn
Find "00"
IfFound
HexOff
UnicodeToASCII
Else
HexOff
EndIf
Top
Find "----------------------------------------^p"
Replace All ""
Find RegExp "%Find '*^p"
Replace All ""
Find RegExp "%Found '*^p"
Replace All ""
Find RegExp "/[0-9]+:*$"
Replace All ""
SortAsc IgnoreCase RemoveDup 1 -1 0 0 0 0 0 0
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4062
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Grep: find files in directory4string & log filename to file

Postby Bego » Thu Nov 09, 2006 3:29 pm

Simply use "Find in files" in the search menu (i think it is F4 by default)

rds Bego
User avatar
Bego
Master
Master
 
Posts: 357
Joined: Wed Nov 24, 2004 12:00 am
Location: Germany


Return to Macros