From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tomas Nordin Newsgroups: gmane.emacs.help Subject: EB double-grep function for bash Date: Tue, 19 Jul 2016 22:43:10 +0200 Message-ID: <87zipdgy01.fsf@debian.tompa.tv> References: <868tx2rrh5.fsf@student.uu.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1468961802 17844 80.91.229.3 (19 Jul 2016 20:56:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 19 Jul 2016 20:56:42 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jul 19 22:56:33 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1bPc47-0001gn-26 for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Jul 2016 22:56:31 +0200 Original-Received: from localhost ([::1]:58837 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPc46-0000bf-B9 for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Jul 2016 16:56:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPbrX-0007dZ-Bm for help-gnu-emacs@gnu.org; Tue, 19 Jul 2016 16:43:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPbrT-00062T-A1 for help-gnu-emacs@gnu.org; Tue, 19 Jul 2016 16:43:30 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:52082) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPbrT-0005xW-37 for help-gnu-emacs@gnu.org; Tue, 19 Jul 2016 16:43:27 -0400 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 48A0F20E2F for ; Tue, 19 Jul 2016 22:43:14 +0200 (CEST) Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 3rvBns3wnJzytr for ; Tue, 19 Jul 2016 22:43:12 +0200 (CEST) Original-Received: from tomas by debian with local (Exim 4.84_2) (envelope-from ) id 1bPbrC-0000AB-Gy for help-gnu-emacs@gnu.org; Tue, 19 Jul 2016 22:43:10 +0200 User-agent: mu4e 0.9.17; emacs 24.4.1 In-reply-to: <868tx2rrh5.fsf@student.uu.se> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 185.67.36.66 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:110894 Archived-At: 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=($@[5,-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