Well, it's not a tutorial, but how's this?
PHP Code:
<?php
$target_file = 'source.txt';
$output_file = 'target.txt';
//Open the target file for read-only mode.
$fh = @fopen($target_file,'r');
if ($fh) {
//Open the output file for writing.
$ofh = @fopen($output_file,'w');
$nl_prefix = ""; //Will hold newline as a prefix for all lines after the first
while (!feof($fh)) {
$a_line = fgets($fh); //Get a full line until a newline is received.
$a_line = trim($a_line); //Remove any extraneous space that may be present on a blank line
if (strlen($a_line) > 0) { //This was an empty line, so skip processing.
//Now, do what you want to the data. In this case, it's parsing SQL, so let's use preg_match
preg_match_all('/([a-z0-9\_\-]+) = `([^`]+)`/i',$a_line,$matches);
if (count($matches[1]) > 0) { //Then, there are matches
//Now, generate a new output line (id:name:password)
$output_line = $nl_prefix.$matches[2][0].':'.$matches[2][1].':'.$matches[2][2];
//Then, write it to the new file.
fwrite($ofh,$output_line);
//Set newline prefix for non-first lines.
$nl_prefix = "\n";
}
}
}
//Cleanup by closing each of the open files
fclose($fh);
fclose($ofh);
} else {
echo 'Unable to open file';
}
?>
Oh, let me point out that to customize this for your own usage which may have a different file format, you "just" need to edit the preg_match_all line to the RegEx of your choice.