Open Source Research and Development

Free and Open Source R&D Projects, Articles, and Reviews

Year: 2009

Negation in regular expressions

How to search for lines that don’t contain a particular pattern is fairly easy in some programs, obscure in others, and almost impossible yet in others. That is, assuming your program of choice supports regular expressions. I review how to achieve this functionality in Perl, Vim, grep, and vi.

Why grep ‘foo|bar’ file doesn’t work?

The bar | has no special meaning in BRE (basic regular expressions). Use extended regular expressions (ERE) such as: grep -E ‘foo|bar’ file or egrep ‘foo|bar’ file In GNU grep, you can also force the spcial meaning of | by escaping it. E.g., grep ‘foo\|bar’ file

Is grep an acronym? Does it mean GNU Regular Expression P?

grep originated from ed command: g/re/p where re is a regular expression, g stands for globally, and p stands for print. So one could say grep is an acronym of “Global Regular Expression Print“.