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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GREP and AWK with DB

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I need to replace the values in one text file with their corresponding column values in that text field and then update a database table with the new values, anyone got help for a script or structure that would be useful.

the underlying concept.....

ie textfile names.txt(old,new)
patriots pats
louisiana rams


and then update sql such as set name='pats'
where name ='patriots'

however this has to be done on a huge scale as in 10,000 lines in the text file....

any help apprec.....
 
quick Perl script for you.

#!/path/to/perl

$table_name = 'my_table';

while(<>){
chomp;
($f1, $f2)=split(/\s+/);
print &quot;UPDATE $my_table SET name WHERE name = '$f1';\n&quot;;
}

Put it into a file, chmod +x that file and then run it with your text file as a command line parameter.

If you're running on a database with transaction control you'll have to put the occasional commit in there to keep things happy. Put another line in after the print line, line this.

print &quot;COMMIT WORK;\n&quot; if ($. % 100) == 0;

And then as the last line in the script:

print &quot;COMMIT WORK;\n&quot;
Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top