Using FindInFiles to "head" files

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

Using FindInFiles to "head" files

Postby bookman » Tue Jun 06, 2006 6:09 pm

I was trying to use "Find In Files" combined with Perl Regex to extract the first N lines from a group of files, and have the results in an output window.

I can use wildcards to grab a group of arbitrary lines just fine, but if I grab, for instance, 7 lines, and there are 70 lines in the file, I'll get 10 items found. But I only want to see the first one.

Is there any way to anchor a regex at the top of the file?
Or tell the routine to stop after the first expression is found in each file?
Or any other way to do this in UE?
User avatar
bookman
Newbie
 
Posts: 4
Joined: Mon Mar 20, 2006 12:00 am

Re: Using FindInFiles to "head" files

Postby Mofi » Sun Jun 18, 2006 10:44 am

No, this cannot be done with a regex search.

You can use the following macro. It collects the first 7 lines of all opened files with a name (not new files) and paste it with the full file name to a new file. The opened files are saved before the macro really starts because they must be all modified temporarily by the macro and are closed without saving.

InsertMode
ColumnModeOff
HexOff
SaveAll
Clipboard 9
ClearClipboard
Loop
Clipboard 8
IfNameIs ""
ExitLoop
EndIf
CopyFilePath
Top
"

File: "
Paste
"

"
Key DOWN ARROW
Key DOWN ARROW
Key DOWN ARROW
Key DOWN ARROW
Key DOWN ARROW
Key DOWN ARROW
Key DOWN ARROW
SelectToTop
Clipboard 9
CopyAppend
CloseFile NoSave
EndLoop
ClearClipboard
NewFile
Clipboard 9
Paste
ClearClipboard
Clipboard 0
Top
Key DEL
Key DEL
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4054
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Using FindInFiles to "head" files

Postby bookman » Tue Jun 20, 2006 7:41 pm

Thanks, Mofi. I'll give it a try and see how it does. I appreciate the help!
User avatar
bookman
Newbie
 
Posts: 4
Joined: Mon Mar 20, 2006 12:00 am


Return to Find/Replace/Regular Expressions