Setting local vars from a header rec in another file?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Setting local vars from a header rec in another file?
# 1  
Old 07-25-2005
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.
# 2  
Old 07-26-2005
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
# 3  
Old 07-26-2005
more info

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

Last edited by ecupirate1998; 07-26-2005 at 03:33 PM..
# 4  
Old 07-27-2005
Quote:
Originally Posted by ecupirate1998
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.

Code:
#! /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
# 5  
Old 07-27-2005
thanks

Thanks for the reply
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find header in a text file and prepend it to all lines until another header is found

I've been struggling with this one for quite a while and cannot seem to find a solution for this find/replace scenario. Perhaps I'm getting rusty. I have a file that contains a number of metrics (exactly 3 fields per line) from a few appliances that are collected in parallel. To identify the... (3 Replies)
Discussion started by: verdepollo
3 Replies

2. AIX

Setting up Local printer AIX 5

Hi folks need some help here. We have a RS6000 running AIX. It is almost never used anymore, but we need to print off some data. I have a paralell printer conected to the parrallel port, but have no idea where to go from here. The printer was originall named named LP01. If the users telnetinto the... (2 Replies)
Discussion started by: prator
2 Replies

3. Shell Programming and Scripting

Comparing one file header with another file header

Hi Experts, In our project we have requirement where in we have to compare header of one file with header in the parameter file. There are 20 files which we ftp from one site. All this files have different header. We are comapring this file with our parameter file(which is having the header... (2 Replies)
Discussion started by: Amey Joshi
2 Replies

4. Solaris

Setting up local DNS Server

Hi , Could some one please share some docs or steps to set up solaris box as a local DNS . Thx (1 Reply)
Discussion started by: skamal4u
1 Replies

5. Shell Programming and Scripting

Set lines of in a file to seperate vars

In a bash script, I'm looking for a way to set each matching line of a file into its own variable, or variable array. As an example, i have a crontab file with several entries: 00 23 * * * /usr/local/bin/msqlupdate -all 00 11 * * * /usr/local/bin/msqlupdate -inc 00 03 * * *... (2 Replies)
Discussion started by: lochraven
2 Replies

6. Linux

Reading the header of a tar file(posix header)

say i have these many file in a directory named exam. 1)/exam/newfolder/link.txt. 2)/exam/newfolder1/ and i create a tar say exam.tar well the problem is, when i read the tar file i dont find any metadata about the directories,as you cannot create a tar containig empty directories. on the... (2 Replies)
Discussion started by: Tanvirk
2 Replies

7. Shell Programming and Scripting

how to reformat a file to 80 byte rec length?

I have a variable length file that needs to be reformatted to 80 byte reclen before I ftp it to a customer. What is the best way to do this? I tried using dd if=inputfile of=outputfile conv=noblock cbs=80, and it almost gives me what I need. The output file needs to be 80-byte records, and the last... (4 Replies)
Discussion started by: cmgarcia
4 Replies

8. UNIX for Advanced & Expert Users

Send/Rec files via modem..

Ok, here is my situation. I need to send/rec files to different outside sources. A developer working on this couldn't find a unix program to dial out so he is going to go with a 3rd party software on a NT box. eww So, this is what I'm looking for. I would have a modem on a sun/linux/hp box and... (1 Reply)
Discussion started by: natter
1 Replies
Login or Register to Ask a Question