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

awk

Status
Not open for further replies.

elanchezhian

Programmer
Dec 3, 2001
3
IN
How to read from flat file and put it in a database using awk? How to do it?
 

Hi elanchezhian!

awk can work only with text files. You can read from text file and write to text file using awk.

If you wish to read from flat file and put data in a database, you must use special tools of particular database. For example, Oracle tool for this purpose is 'SQL *Loader'.

Bye!

KP.
 
Hi krunek,

I have used sql loader, I know that it works fine with that, but i want to take the fields in a record which is present in a flat file and i should put it in a shell variable and then that should be ported to Database, SO my problem is how to retreive the fields from flat file using awk and put it in Shell variable.
 
Shell variable? Why do you need that?

As Krunek has described..... Parse your ascii file with "awk". The result of "parsing" will be a another ascii file in the format of "SQL Loader" [if you're using Oracle] OR any other format based on the Database technology that you have - I assume you know better what database you have AND what tools/utilities are available.

After you've created a "loadadble" file [as the result of the awk parsing] use the database tools available to you to load the data.

vlad
 
If you are scripting I can see where the dynamic info
could better be retrieved as a variable.

for ii in $(cat file)
do

a=$(echo $ii | awk ' {script}')
test $a && load $a DB
done




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top