Created
February 26, 2010 18:54
-
-
Save jlogsdon/316023 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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