Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Jul 2014 10:44:03 +0200
From:      Polytropon <freebsd@edvax.de>
To:        Arthur Chance <freebsd@qeng-ho.org>
Cc:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: The name "grep"
Message-ID:  <20140707104403.5a0694ff.freebsd@edvax.de>
In-Reply-To: <53BA4F77.60907@qeng-ho.org>
References:  <20140707075443.d47ca06a.freebsd@edvax.de> <53BA4F77.60907@qeng-ho.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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. ;-)


-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140707104403.5a0694ff.freebsd>