5.0

5.0 | 7 ratings Rate this file 30 Downloads (last 30 days) File Size: 25.26 KB File ID: #9647
image thumbnail

grep: a pedestrian, very fast grep utility

by us

 

16 Jan 2006 (Updated 04 Apr 2006)

a unix-like, very fast grep utility to find strings(s) in files of any type

| Watch this File

File Information
Description

a fast grep utility, which finds string pattern(s) in all or selected files of any type in a folder and its subfolders (if the recursion flag -r is set).

file access and string matching are optimized by low-level i/o and string routines.
the recursion algorithm (-r) does not use ML's genpath.

the syntax and options as well as the output closely follow its unix/linux sibling.
string patterns may be defined as regular expressions.

many options allow to fine tune the GREP engine including an extensive set of inclusion/exclusion flags for folders, files, and full paths, which implement a regular expression based wildcard search.

clicking on an underlined text item will open the file at the matching line.

several help levels are implemented

1) quick overview
> grep
> help grep
sparse information about syntax and option flags (see screenshot)

2) extended help
> grep -p
syntax/peculiarities of pattern/file arguments
> grep -e
several examples (see also grepdemo.m)
> grep -f
for programmers: explanation of the second output argument

see the accompanying published M file for instructions and a few typical examples.

MATLAB release MATLAB 7.1.0 (R14SP3)
Other requirements good spirits
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (10)
17 Jan 2006 John D'Errico

It took me a little while to figure out why this function would not work for me. It needs not just release 14 of matlab, but the most current sub-release, due to its reliance on the newest abilities of cellfun. This should be explicitly documented. As for the documentation, I think its a bit confusing to read. At the least, I'd like to see a few additional examples of use.

19 Jan 2006 John D'Errico

Its a bit better now, with the correct release info and better examples. I still can't seriously review it since I can't run it. (I have learned to trust us, so I'll bet it does work.)

25 Jan 2006 John D'Errico

A splendid example of a help document! This is the kind of html help that we should all learn to emulate. Good examples that the user can read, fully explaining what the arguments do in each example.

16 Mar 2006 Malcolm Wood

Very nice tool! Fast and flexible. A suggestion for possible enhancement:
When displaying results in the MATLAB Command Window, create hyperlinks to the relevant lines using, e.g.
disp('<a href="matlab:opentoline(''myfile.m'',99)">myfile.m:99</a>');

04 Apr 2006 Kevin Hung

Very fast and very useful. Have a lot of features (eg. exclude directories). I have no problem running the code.

Also very quick response from the author to implement new features.

16 Aug 2006 Alex Chung

Hi,

Can you tell me how to make it work given the following error message? Thanks.

Alex

>> grepdemo

us
Version
                n=-n;
par.class=t.class;
        if par.opt.c

??? Too many inputs.

Error in ==> <a href="error:/shome/xzhang/Matlab2/grep.m,328,1">grep>set_opt at 328</a>
                ic=cellfun(@(x) [pat,class(x),']'],arg,'uniformoutput',false);

Error in ==> <a href="error:/shome/xzhang/Matlab2/grep.m,109,1">grep at 109</a>
                [p,msg]=set_opt(otbl,p,varargin{:});

Error in ==> <a href="error:/shome/xzhang/Matlab2/grepdemo.m,23,1">grepdemo at 23</a>
        grep -i -n Version grep.m

21 Sep 2006 Jay Dermody

great function. Very useful. Very Fast. Awesome.

08 Nov 2007 Abel Brown

brilliant!!! works right off the bat ... and well. I dont get too many scripts from here that i dont have to mess with before they work on my intel mac. This is perfect! A+ documentation! Now i can finally get rid of my system calls awwwww yeah

05 Jul 2009 Yair Altman

An excellent utility that I have come to rely-on in my daily work over the past few years. As with all the other submissions by Urs, GREP is deceivingly simple, extremely powerful and lightningly fast. If possible, I would suggest to make this utility more unix-compliant in its input flags (and yes, I am aware there are different grep flavors depending on the 'nix version). For example, support of -#/-a/-b etc. would be appreciated. Still, this would only be the icing on the cake since as I said GREP is already extremely powerful as-is.

30 Sep 2009 almog shalom  
Please login to add a comment or rating.
Updates
18 Jan 2006

added a few examples

19 Jan 2006

thanks to john d'errico, summary page now shows the correct ML version (14.3+).

25 Jan 2006

help sections upgraded (request dr john d'errico); e-option now can use string and cell arguments; version tag 25-Jan-2006 14:58:48

10 Feb 2006

many users requested a change of the name from FGREP to GREP since latter can be type much faster; minor changes in the help and example sections

20 Mar 2006

added malcolm wood's suggestion: the user now can click on an underlined list item in the command window to open the file and jump to the line number; version tag 16-Mar-2006 20:22:12

21 Mar 2006

unfortunately, not all files were updated correctly! version tag 21-Mar-2006 13:21:45

30 Mar 2006

clarification on use of -e option arguments; version tag 30-Mar-2006 15:24:10

03 Apr 2006

added an extensive set of inclusion/exclusion options for folders, file names, and combined full paths, which implement a regular expression based wildcard search engine (request by user kevin hung); version tag 03-Apr-2006 00:15:40

04 Apr 2006

now checks in unix-type subfolders that begin with a ., eg, .foo (requested by user kevin hung); version tag 04-Apr-2006 00:31:57

Tag Activity for this File
Tag Applied By Date/Time
path us 22 Oct 2008 08:12:40
directories us 22 Oct 2008 08:12:40
files us 22 Oct 2008 08:12:40
search us 22 Oct 2008 08:12:40
pattern us 22 Oct 2008 08:12:40
string us 22 Oct 2008 08:12:40
file us 22 Oct 2008 08:12:40
folder us 22 Oct 2008 08:12:40
directory us 22 Oct 2008 08:12:40
regular expression us 22 Oct 2008 08:12:40

Contact us at files@mathworks.com