How did grep
get its name? This all starts back with ed
, the original unix
editor. ed was a command-line editor that worked identically to the
colon-commands in vi and vimβin fact, you can press Q
to get into ed mode
(then type vi
to get back into vim). From the ed editor you can issue common
line-oriented commands like s, d, y, and so on:
:%s/rdoc/docr/g
:/include/d
If youβre following along at home you may wonder βhow can I see the contents of
this file?β Well if you just want to see every line you can use %p
(%
is
βthe whole fileβ, and p
is βprint to screenβ), though itβs more likely that
you want to see a small series of lines. 10,20p
will show you lines 10
through 20, but maybe it makes more sense to see all lines matching a regular
expression.
From ed, to see all lines matching βincludeβ, use g/include/p
. To see all
lines matching βdocrβ use g/docr/p
. In general, to see all lines matching
the regular expression βreβ, use g/re/p
.
β¦ And thatβs how grep got its name.
Whatβs next
If you like Unix and Vim history, you might also enjoy: