Re: You guys will find this easy...
| From: | Joe Stump | Date: | Tue, 05 Dec 2000 09:05:53 +0000 |
| Subject: | Re: You guys will find this easy... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28699@lists.php.net to get a copy of this message | ||
Well you will want to combine bash and php - so here goes!
in parse.php:
<?
$fp = fopen('/dev/stdin','r');
while(!feof($fp))
{
$info[] = trim(fgets($fp,4096));
}
while(list($key,$val) = each($info))
{
// add the a because you can't have vars start with nums
$key = 'a'.$key;
$$key = addslashes($val);
}
// echo the $sql out
// $a1 = id
// $a2 = email
// $a3 = url
$sql = "INSERT INTO your_table (id,email,url) VALUES
('$a1','$a2','$a3')";
echo $sql."\n";
?>
The above file takes in a file with only THREE lines in it (as described below)
Now your bash script
in loop.sh:
#!/bin/sh
for i in
ls .
do
cat $i | php -q parse.php >> queries.sql
done
All that is left is to put all those text files in one dir and run loop.sh
--Joe
On Tue, Dec 05, 2000 at 07:53:47AM -0000, jalist wrote:
> This is a real newbie question, but it has me a bit stuck...
> I have a large number of text files in this format...
> Line 1: ID number
> Line 2: email addy
> Line 3: website url
> The files are named as the username, eg bob.user.
> What I want to do is sort the files by the id number so I can load the info
> into a mysql db, which obviously involves looping through all the files and
> checking the id number on the first line. I've been messing with this for a
> while now and can't seem to get it right.
> Any help very welcome, and thanks.
>
> Steve
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
-----
Joe Stump, PHP Hacker
joestump98@yahoo.com
http://www.miester.org/
Need a programmer? http://www.google.com/search?q=%22Joe+Stump%22
*****************************************************************
* RENT THIS SPACE - SEEN BY THOUSANDS EACH DAY! *
* Current Sponsor: http://www.smackdown.com
*
*****************************************************************