OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

Negation

If the first character in a bracket expression is a caret (^), the remaining characters are taken to be a set of characters that must not be present at the given character position. We do this by modifying our previous example:



[me@linuxbox ~]$ grep -h '[^bg]zip' dirlist*.txt

bunzip2

[me@linuxbox ~]$ grep -h '[^bg]zip' dirlist*.txt

bunzip2


gunzip funzip gpg-zip preunzip prezip

prezip-bin unzip unzipsfx

gunzip funzip gpg-zip preunzip prezip

prezip-bin unzip unzipsfx


With negation activated, we get a list of files that contain the string “zip” preceded by any character except “b” or “g”. Notice that the file zip was not found. A negated character set still requires a character at the given position, but the character must not be a member of the negated set.

The caret character only invokes negation if it is the first character within a bracket ex- pression; otherwise, it loses its special meaning and becomes an ordinary character in the set.


Top OS Cloud Computing at OnWorks: