Learn R Programming

Kmisc (version 0.2.0)

ngrep: Inverse grep

Description

From a vector x, return only the elements that do not satisfy a particular regular expression statement; ie, remove all elements that are matched by pattern.

Usage

ngrep(pattern, x, ...)

Arguments

pattern
regular expression pattern
x
vector of items to match against
...
passed to grep

Value

  • the elements in x that did not match the pattern supplied

Details

Note that, by default, grep returns the location of matches, rather than the actual matches themselves. ngrep only returns matched elements, not the location of matches.

See Also

grep regex

Examples

Run this code
some_files <- c("output_file.tar.gz", "old_log1.txt", "old_log2.txt")
## get the non-log files
files_I_want <- ngrep( "_log[0-9]+\\.txt$", some_files )

Run the code above in your browser using DataLab