Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


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

What does grep stand for?



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

- -----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Scott Prive" <scottprive at earthlink.net> writes:

> > g/[re]/p
> 
> Obviously re is regular expression... but what's g and p (or g/ /p)?

My first exposure to Unix was Version 7 on a PDP-11/34a, back in 1983; 
the grep command already existed by then, and as I recall, its man page 
explained that in prior versions of Unix, users would use "ed" to do 
pattern searches using the "g/[re]/p" syntax. Presumably the first 
implementation of grep was a simple shell script that invoked ed, 
something similar to the following:

    #! /bin/sh
    RE="$1"
    shift
    for filename do
    ed - $filename << "EOF"
    g/"$RE"/p
    EOF
    done

line or range of lines specified as a prefix to the command. If you 
specified a line, the default command was to set the current line 
to that line silently. The "p" command would print the current line. 

The "/[re]/" command would search for the next occurrence of a line 
matching the pattern "[re]" and set the current line to that line, 
and if it was followed by a command, it would then run that command. 
So, for instance, "/^$/d" would delete the next blank line. 

The "/[re]/" command also had "g" and "v" prefixes: "g/[re]/" would 
match every line that matched the pattern, and "v/[re]/" would match 
every line that didn't match the pattern. 

"g/[re]/p" would therefore find all lines that matched the pattern 
and print them, and "v/[re]/p" would find all lines that didn't 
match the pattern and print them. That's also why the grep command
uses "-v" to negate the search pattern; that also comes from ed. 


- - --
John Abreau / Executive Director, Boston Linux & Unix
Email jabr at blu.org / WWW http://www.abreau.net / PGP-Key-ID 0xD5C7B5D9
PGP-Key-Fingerprint 72 FB 39 4F 3C 3B D6 5B E0 C8 5A 6E F1 2C BE 99


- -----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Exmh version 2.6 02/09/2003

iQCVAwUBPtwU9VV9A5rVx7XZAQIWDAQAxInbsdUJdH2LD9zn6lJTb57/EHDLW0IN
GOfVQmIADG//Sh85vRcp2rCpZiPDPQGCDdhP1QIF+FgFBbdkDsQFVFzGzd3YjmGM
yCsC4wEuQXRm7j6pnndMlQhe5Rc97kmT5/c4LtjpdYOVtOhSg7OOcSU9I0i2tFBr
sFbSFJXwbpM=
=qh/a
- -----END PGP SIGNATURE-----



- --
John Abreau / Executive Director, Boston Linux & Unix
Email jabr at blu.org / WWW http://www.abreau.net / PGP-Key-ID 0xD5C7B5D9
PGP-Key-Fingerprint 72 FB 39 4F 3C 3B D6 5B E0 C8 5A 6E F1 2C BE 99


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Exmh version 2.6 02/09/2003

iQCVAwUBPtwVQlV9A5rVx7XZAQJRcgP/a5zjvcV9rP9/KX8l5b6OQwtm+IlcaSra
IU5Z8RxQmOeTxBFbyVwDRFG8Clr/dGaX9GR1JmHy2oEuK8mMZSPZg79ktQkFYwM1
SuENk9IOFCf3aPK7YYeT+DeSjGKoif7jZ1fe46zXx+VkHs1lRU5byBo4LWkMGvqR
0ME2BvcGRxA=
=5czb
-----END PGP SIGNATURE-----





BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org