From owner-freebsd-questions@FreeBSD.ORG Mon Jul 7 10:08:44 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1750E17D for ; Mon, 7 Jul 2014 10:08:44 +0000 (UTC) Received: from blue.qeng-ho.org (blue.qeng-ho.org [217.155.128.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 88BE122F8 for ; Mon, 7 Jul 2014 10:08:43 +0000 (UTC) Received: from fileserver.home.qeng-ho.org (localhost [127.0.0.1]) by fileserver.home.qeng-ho.org (8.14.7/8.14.5) with ESMTP id s67A8d1J003854; Mon, 7 Jul 2014 11:08:39 +0100 (BST) (envelope-from freebsd@qeng-ho.org) Message-ID: <53BA71A7.9040208@qeng-ho.org> Date: Mon, 07 Jul 2014 11:08:39 +0100 From: Arthur Chance User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: Polytropon Subject: Re: The name "grep" References: <20140707075443.d47ca06a.freebsd@edvax.de> <53BA4F77.60907@qeng-ho.org> <20140707104403.5a0694ff.freebsd@edvax.de> In-Reply-To: <20140707104403.5a0694ff.freebsd@edvax.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: FreeBSD Questions X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Jul 2014 10:08:44 -0000 On 07/07/2014 09:44, Polytropon wrote: > On Mon, 07 Jul 2014 08:42:47 +0100, Arthur Chance wrote: >> From ancient memory circa 1980, probably suffering from bit rot: >> >> Before grep existed, to use ed to print lines in a file that match a >> particular regular expression >> >> ed $file >> g/re/p >> q >> >> where the "re" stands for the regular expression and you're applying the >> "p" (print) command to each line that matches it. > > Yes, I already thought this was related to ed (discussed in the > same book at a previous occassion, and refered to as "the editor", > prior to introducing vi). So "r" and "e" aren't acutual commands > (p is a command, "print", g a modifier, "global"), but > refers to "put regular expression here". > > Having another seizure that forced me to read "man ed", I found > some "re" entries: > > (.,.)s/re/replacement/ > (.,.)s/re/replacement/g > (.,.)s/re/replacement/n > \(re\) > > The two important entries are: > > (1,$)g/re/command-list > Apply command-list to each of the addressed lines matching a reg- > ular expression re. The current address is set to the line cur- > rently matched before command-list is executed. At the end of > the g command, the current address is set to the last line > affected by command-list > > and > > (.,.)p Print the addressed lines. The current address is set to the > last line printed. > > There is the "re" of "g/re/p", leading to the understanding what > "grep" basically means (even though it offers much more functionality > as a stand-alone tool, of course). > > > >> When a newbie asked how to print matching lines in a file, you'd answer >> "grep" and show them the trick, and eventually the name got given to the >> grep program when it was written. I think the "global regular expression >> print" explanation is based on explaining what the original ed command did. > > And I have actually _tried_ that with /bin/ed - it works! So > should the "grep" manpage (and maybe other manpages, too) > contain a hint on where the program name originates from? > In my opinion, this would be a good place to put such kind > of information because manpages are a "condensed form" of > wisdom, available locally, for reference, study, and overall > education. Global Real Education, Pal. ;-) It's of historical interest, but 30+ years down the line, when only sysadmins know ed for emergency use, I doubt whether it really matters that much. I suspect most Unix programmers today would respond in much the same way as my nephew (born about the same time as OSF/1) responded to my explanation of what "45s and 33s" were - part "hmm, interesting but seriously obscure fact" and part "jeez, was that like the Stone Age or something?" :-)