Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Feeder file creation 4

Status
Not open for further replies.

KenCunningham

Technical User
Mar 20, 2001
8,475
GB
Good day to all,

I've been creating a feeder file using Access and am currently stuck in obtaining the correct format. The feeder needs to be in the format:

8000107188 61 0100000000000.01CT05-FEB-2002

8000107178 01 0100000000000.01CT05-FEB-2002

8000107379 81 0100000000000.01CT05-FEB-2002

8000108879 11 0100000000000.01CT05-FEB-2002

8000107166 71 0100000000000.01CT05-FEB-2002

8000115416 51 0100000000000.01CT05-FEB-2002

but so far using my Access export, I am not getting the decimal point from my original file. Rather than mess around any more in Access, I hope to go native and use a solaris script to insert the decimal point appropriately. Clearly, it will need to be inserted two digits before the CT in the third string above, so that my current output:

6049764501 62 PP00000000001500CT02-Apr-2002

becomes:

6049764501 62 PP00000000015.00CT02-Apr-2002

Can anyone think of a relatively easy way of doing this? Many thanks in advance.

 
Perl?

while(<>){
s/CT/.CT/;
print;
}
Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
nawk -F &quot;CT&quot; -v OFS=&quot;CT&quot; '{$1=substr($1, 1, length($1)-2) &quot;.&quot; substr($1,length($1)-1); print }'
 
sheeesshhhh - I knew there was a reason I didn't like awk.... :) Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Obviously this data will be read into a program. Why can't you just read the dollar amount into a temporary long and then divide by 100 to set the real value?

Another thing I see is that your data is in fixed length format. Rather than using awk or perl that must look for some R.E., it would probably be more prudent to use cut to slice the data in a fixed location and insert the decimal point that way:

Code:
cut -c -29 file1 > file1.tmp1
cut -c 30- file1 > file1.tmp2
paste -d&quot;.&quot; file1.tmp1 file1.tmp2 > file2

This scripts creates two slices of the file (before and after where the decimal point is to go), and then pastes them back together. I had to guess on the 29 and 30 as far as locations of the cut (your spacing didn't display too well). Also, I don't know if having two extra files is acceptable to you. I couldn't get the cuts and paste to work on a single line.

Good luck. Einstein47
(Love is like PI - natural, irrational, endless, and very important.)
 
hmmmmm.......
Why having 2 TEMP files and having to deal with POSITIONAL dependencies is ANY better than specifying a more generil RE with in sed/awk/perl?

 
Thanks Guys! As usual there's always more than one way to skin a cat. Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top