Skip to content

Instantly share code, notes, and snippets.

@jlogsdon
Created February 26, 2010 18:54
Show Gist options
  • Save jlogsdon/316023 to your computer and use it in GitHub Desktop.
Save jlogsdon/316023 to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
/**
* `grep` is faster for single terms.
*
* `grep -i .php /path/to/access.log`
*
* vs.
*
* `this-script /path/to/access.log .php`
*/
$script = array_shift($argv);
$file = array_shift($argv);
if (!$file) {
echo "Usage: {$script} <file> <retain...>\n\n";
exit;
}
if (!is_file($file)) {
echo "Error: {$file} does not exist\n\n";
exit;
}
$retain = $argv;
if (empty($retain)) {
echo "Error: nothing to retain. You must specify at least one string to retain.\n\n";
exit;
}
$fp = fopen($file, 'r');
while ($line = fgets($fp)) {
foreach ($retain as $search) {
if (stripos($line, $search) !== false) {
echo $line;
continue 2;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment