Setting local vars from a header rec in another file?

Hey guys,

We are going to be receiving files containing header information. This will be 1 line of code in each file containing the following format:

20050719hhmmsssfgr00310000537000000000000000

My question is...How can I pull parts of the header info and set it to vars in my shell. I will be inserting this information into an Oracle Table.

Also, contained in the header information, is the total amount of records contained in the file. Somone suggested that I could compare this amount with the sqlldr info. Any ideas on how I could do this?

If you are in the Columbus area. I will pick up the beer tab for this one.

Thanks much.

An approach I picked up from this post.

Look at Perderabo's solution.

20050719hhmmsssfgr00310000537000000000000000

If the orientation of data presented in that header information is always the same, then, why dont you look for the first n characters, or n characters starting from k-th postion etc.

Vino

I'm hoping this is a good way to code this. Any comments?

read var < sfgr0031.dat

echo $var

v1=`echo $var | cut -c 1-14`
v2=`echo $var | cut -c 15-22`
v3=`echo $var | cut -c 23-29`

echo $v1
echo $v2
echo $v3

There is nothing wrong as such in your method. But you can avoid external calls altogether and use the shell builtins.

Inside your script do this.

#! /bins/sh

read var < sfgr0031.dat
echo $var

v1=${var:0:13}
v2=${var:14:8}
v3=${var:22}

echo $v1
echo $v2
echo $v3

Check out man sh under the sub-title Parameter Expansion.

Vino

Thanks for the reply