If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Retrieve name, run sql and load data.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-08-10, 15:50
email.adubey email.adubey is offline
Registered User
 
Join Date: Jan 2010
Posts: 1
Retrieve name, run sql and load data.

Hi all,
I am new to scripting. I want to automate things.
I get file named as NY.csv, CA.csv,FL.csv in folder /apps/data. Now these NY,CA and FL have existing data in two tables.
1. I want to retrieve the name NY first from the filename
run 2 queries:
delete * from TABLENAME1 where state='retrieved name from file i.e.(NY)';
commit;
delete * from TABLENAME2 where state='NY';
commit;
and load the new NY.csv via crontab ( i already have the crontab setup done) . then do the same for CA and then for FL.


Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 01-08-10, 18:00
kitaman kitaman is offline
Registered User
 
Join Date: Sep 2009
Location: Ontario
Posts: 526
Code:
!#/usr/bin/ksh
cd /apps/data
list=`ls ??.csv`
for file in $list
do
   state=`echo $file|cut -d"." -f1`
   sqldelete1 $state
   sqldelete2 $state
   sqladd3 $file
done
You should also consider that there may be PA.csv that should not be processed.
The entire process should be in your cron job.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On