Find Last record in the file

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
srini
Charter Member
Charter Member
Posts: 3
Joined: Fri Apr 12, 2002 5:29 am
Location: Texas

Find Last record in the file

Post by srini »

Hi all

I need to find out the last record for a dynamic sequential file(can have
variable count). Is there a built-in routine or transform in datastage to
perform this process???

Thanks in advance


Srini
roy
Participant
Posts: 2598
Joined: Wed Jul 30, 2003 2:05 am
Location: Israel

Post by roy »

Hi,
you can use basic to open the file then skip to the end of the file in a relative number of rows using the seek statement hence getting to the last line, which can then be read.
all you need is in the basic.pdf in your client install path under docs
another way is to use the filter command in the seq file having tail -1 <file> in it (you might need the full path of the tail command).
another way is to use shell script or command to perform the same tail and redirect the output to a file then read it.
there are perhaps more variations of this so take your pick :)

IHTH,
Roy R.
Time is money but when you don't have money time is all you can afford.

Search before posting:)

Join the DataStagers team effort at:
http://www.worldcommunitygrid.org
Image
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

wc -l file

will tell you quickly how many rows are in a file.
Mamu Kim
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

The tail -1 filename would be the fastest of those recommended. It could return the row back to the calling routine for processing. tail -1 filename > filename would let you write out the last row to a new file for processing in DataStage.
hexa
Participant
Posts: 51
Joined: Sun Aug 08, 2004 6:25 am

Use Aggregator and Transformer

Post by hexa »

Hi

I hope ur record has a primary key
u can use the aggregator stage to find the last value of this column in your file. u can also use some other column that will have a unique value.
Later u can use the transformer stage and place a constaint to add only that record to the output file which has that unique id

I hope this solves your problem
Post Reply