convert strings in a file to integer

I got a file with a lot of numbers that are strings. I'd like to read all
this numbers and convert them to numbers for futher compareation. How can I
convert all this numbers to integer?

regards
frengky

--
Organisation nr: 983063349
Frengky, Olsokveien 65,1727 Sarpsborg, Norway
Tel: +47 92611725
Fax: +47 69152017
Email: oystein.western [at] frengky.no
Web: www.frengky.no
info [ So, 09 Januar 2005 18:51 ] [ ID #575769 ]

Re: convert strings in a file to integer

�stein Western wrote:

> I got a file with a lot of numbers that are strings. I'd like to read all
> this numbers and convert them to numbers for futher compareation. How can
> I convert all this numbers to integer?
>
> regards
> frengky
>

Hi

Easiest way: Use some sciptinglanguage.
PHP or Perl or something like that.
(I prefer PHP)

Just open the file, get the numbers out, and create a whole bunch of
INSERTS.
Then execute.

In PHP, use the file() command to retrieve all the lines in an array.
for example:
(Some fantasycode)

$myLines = file("/home/stein/somenumbers.txt");
$SQL = "";
for($i=0;$i<count($myLines);$i++){
$myNum = (int)$myLines($i);
SQL .= "INSERT INTO tblnumbers (anumber) VALUES (".$myNum.");\n";
}

pg_execute($SQL);
or
echo replace("\n","<br>",$SQL);


Something like that.

Good luck!
Regards,
Erwin Moller
Erwin Moller [ Mi, 12 Januar 2005 13:31 ] [ ID #581386 ]
Datenbanken » comp.databases.postgresql.sql » convert strings in a file to integer

Vorheriges Thema: sql problem
Nächstes Thema: Real Election Reform