Created
June 21, 2011 21:21
-
-
Save cbednarski/1038932 to your computer and use it in GitHub Desktop.
Filter a file using a regex pattern
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
<?php | |
// This script filters the specified file over the specified regex pattern | |
// Each line that matches will be included in the new file | |
$source = fopen(__DIR__.'/sourcefile.csv', 'r'); | |
$target = fopen(__DIR__.'/targetfile.csv', 'w'); | |
while($line = fgets($source)) | |
{ | |
if(preg_match('#^pattern$#', $line) > 0) | |
{ | |
fwrite($target, $line); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment