Tuesday, October 6, 2009

Using sed to search and replace a token without opening a file

#!/bin/bash

i=0; while [ $i -le 47 ]

do

echo " Creating temp file for slice : $i"

sed s/slicenum/$i/g adspace_buy.ctl > adspace_buy.ctl.tmp

echo " Loading Started ..."

sqlldr userid=tfr_rep/welcome@datagen1-aswain:1521/tfrdb control=adspace_buy.ctl.tmp data=adspace_buy_data.$i.csv log=logssqlldr_log_adspaceBuy.log bad=logssqlldr_bad_adspaceBuy.log direct = true

echo "Loading Done for slice : $i"

i=`expr $i + 1`

done

echo "Script completed"

This script will search for a token slicenum in
adspace_buy.ctl file and replace it with $i value of the loop counter. Also it redirects the output to a new file adspace_buy.ctl.tmp.
After that this script uses sql loader utility to load the data to oracle database using this newly generated file. This whole process continues for 48 times.

Sphere: Related Content

0 comments: