Giter VIP home page Giter VIP logo

gf's Introduction

gf

Grep for a pattern in files returned by find

Usage

gf  [PATH]...  [-e] PATTERN | -f PAT_FILE  [PATH]...
    [ NAME | ^EXCLUDE | GREP_OPT ]...

gf  [-e] PATTERN | -f PAT_FILE
    [ NAME | ^EXCLUDE | GREP_OPT | FILE ]...

Description

Use find to search for files in the current directory or the given PATH's, then grep in found files for a regular expression PATTERN. The set of files to search in can be refined by one or more filename patterns NAME and EXCLUDE. Options to grep also follow the pattern. The first usage form is same as:

find [PATH]... [ ! -path "*EXCLUDE*" | -iname NAME ]... -type f \
  -print0 | xargs -0 grep [ -e PATTERN | -f FILE ] [GREP_OPT]...

If this script is run with a name starting with "e", egrep will be used; likewise for "f" and fgrep, and "p" and grep -P. In addition to grep regular expression syntax, the character escapes \s, \d, \S, and \D, when not inside a bracket expression, are replaced with their character class equivalents [[:space:]], [[:digit:]], etc.

The second usage form relies on no PATH's and at least one existing FILE on the comand line, and can be used in conjunction with xargs or command-line expansion to filter results:

ls | xargs -r  gf  PATTERN  "*.py" ^foo
gf  PATTERN  "*.txt"  `cat filelist`

This also allows xargs to run grep with default options, which are defined in $GREPOPTS in this script if it hasn't been exported.

Options

-h, --help      display this help message and exit
-e  PATTERN     use PATTERN as the pattern
-f  PAT_FILE    read patterns from PAT_FILE

Examples

gf  "retrasad[oa]"  -in -C 2  README*
gf  ~/foo/src  '\(import\|from\) popen\d'  "*.py"  ^/.svn/  -l

gf's People

Contributors

bmdavll avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.