help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

EB double-grep function for bash


From: Tomas Nordin
Subject: EB double-grep function for bash
Date: Tue, 19 Jul 2016 22:43:10 +0200
User-agent: mu4e 0.9.17; emacs 24.4.1

Emanuel Berg writes:

> Here is the function:
>
>     double-grep () {
>         local first=$1    # e.g., trim   (most unusual concept first!)
>         local second=$2   #       string (the the more usual...)
>
>         local context=$3  #  0 => no context: hits must be on same line
>         local results=$4  # 10 => show max 10 (double) hits
>
>         local -a files
>         files=(address@hidden,-1])  # e.g., ~/sw/emacs24-24.4+1/lisp/**/*.el
>
>         grep       --color=always -C $context $first  $files \
>             | grep --color=always             $second        \
>             | head -n $results
>
>         # invocation example:
>         #
>         #   $ cd ~/sw/emacs24-24.4+1/lisp/
>         #   $ double-grep trim string 0 10 **/*.el
>     }

Since the thread strayed away a little from emacs already... I made a
little change on two lines in this function to make it run with bash. (I
think the array subscript is a zsh thing). Here's the lines:

        local files
        files=${@:5:$#}  # e.g., ~/sw/emacs24-24.4+1/lisp/**/*.el

--
Tomas Nordin | (The computing freedom explorer)
GPG Key: AB09AF78



reply via email to

[Prev in Thread] Current Thread [Next in Thread]