Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

merging 2 files in a table

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Hi all,
I have to create a mySql table which should take input from two text files; "a.txt" and "b.txt".
For example "a.txt" contains
hostname hostid

and "b.txt" is
cpuload mem scanrate

now, mySQL table should look like

hostname
hostid
cpuload
mem
scanrate

Is there anyway I can populate the mySQL table using these two text files ?
Thanks.
 
Hi,

i would do something like
open (file_A,...);
@a=<file_a>;
open(file_b,...);
@b=<file_b>;
close(file_a,file_b);

I can only assume that
the length of @a=@b (same numbers of line);
so
for ($line=0; $line<@a; $line++) {
chomp $a[$line];
chomp $b[$line];
$new_row= &quot;$a[$line]&quot;.&quot;|&quot;.&quot;$b[$line]&quot;;
@split_row=split(/\|/,$new_row);
$sti=$dbh->prepare(&quot;insert into YOUR_TABLE values(?,?,?,?,?)&quot;)|| dienice(&quot;Error occure while preparing&quot;); #
$sti->execute($split_row[1],$split_row[2],$split_row[3],$split_row[4],$split_row[5]) || die(&quot;Error while executing updates&quot;);
$sth->finish;
}


Should work

Anthony
 
Thanks Antony for the reply.
I was wondering if there is anyway from &quot;load&quot; command which can help accomplish this. Insert command typically runs a lot slower because the files in consideration are &quot;big&quot; ones.
Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top