Unix Guru : The birth of Unix grep command for string search

Ken and Richie on a computer. 
(Image courtesy: Wikimedia Commons)

"Have you ever thought where 'grep' came from?" I asked the Unix Guru Old Nick one morning. The mood of the day was sombre. The sky was overcast, and there was a faint feeling of drizzle, even though there was none. I though it was a great time to get some history lesson.

Nick took a large gulp of his coffee, and cleared his throat.

"How often do you use grep?" he asked.

"Why, every day," I said. "I am always looking for something. I find it to be the most useful Unix command, just behind 'rm -r'."

Nick chuckled at that. I knew he would.

"At the beginning of the epoch, there was the editor 'ed'," Nick began. "But that you know well. If you wanted to search for a pattern, you just opened the file in ed, and searched within it. This was time-consuming if you wanted to search over a multitude of files. Apparently, Ken Thompson got tired of it, and essentially modified the assembly language version of ed to do only regular expressions and called it 's', later on renamed to grep. Thats the short and sweet version of how grep was born."

"But why grep?" I persisted.

"Oh that!" Nick said. "Thats because in ed, to search you used an expression such as 'g/<regular-expression>/p', or, in short, 'g/RE/p'."

"Thats a cool story," I said. 

"I know," Nick smiled. "At least thats how the story goes."



Popular Posts