Reading a pipe delimited file and loading teradata

Hi,

I am new to UNIX shell scripting (KSH). I have a file in UNIX server which is delimited by |.

I require the basic syntax to:

  • read the file
  • move it to a local variables
  • load a database - Teradata

Continue until end of file.

Note: if the field is have no value inbetween two pipes '||', it should be loaded as NULL in the table.

Please help me out.

you are new to ksh, so have you read anything on that before attempting to solve this?

I am trying to find a proper online help book but could not get a good one.

Hi Shiva,
Please let me know, how you are loading the fine in TERADATA. Using fast load or multiload or ?

As per your question, i think u can find and replace two pipe lines as |NULL|.
For this use sed :

sed 's/||/|NULL|/g' filename > newfilename

Now start loading.
Thanks
Javeed Sunar

and what if the FIRST or the LAST field is empty?

Hi,

I am loading it using MLOAD...

the first and last field would never be empty

I know nothing about Teradata, but I assume it has a tool like Oracle SQLLoader capable to load a table from a flat csv or fixed width file.
So, to what purpose would you like to capture values in shell variables?

Anyway, to capture lines composed of 3 fields, the basic loop should be as the following:

myfile=$1

IFS='|' while read -r f1 f2 f3
do
  print "Do whatever you want with $f1, $f2, $f3"
done < $myfile

Of course if the field values are quoted when they contain the "|" character meaning itself, then the problem becomes much worse.