Read the last line of a 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
kasia
Participant
Posts: 26
Joined: Wed Jan 29, 2003 2:02 am
Location: Bordeaux, France

Read the last line of a file

Post by kasia »

Hi all

I have to read the last line of a (dos) file (more exactly - the last ten caracters of the last line).
Begun a routine, but how to go to the last line after the OpenSeq statement?

Or perhaps do you know how to do that through one-line-command in the Before-Job Subroutine field (using ExecDOS)?

fyi, the file is growing (one line added) each time the job is launched

Thanks for help
(see u on Monday :) )
Maveric
Participant
Posts: 388
Joined: Tue Mar 13, 2007 1:28 am

Post by Maveric »

use Status(). It returns a 1 if End of File is encountered. Not sure of syntax though.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

SEEK with the correct argument will get you to the end of the file in a BASIC routine. Then you could back up from there. Or "tail -1" in UNIX or MKS Toolkit.
-craig

"You can never have too many knives" -- Logan Nine Fingers
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Re: Read the last line of a file

Post by gateleys »

A simple google yielded the solution. I tested it and it works. Save the following as a .bat file (since you are working on Windows), and call it from your job.

Code: Select all

@echo off
for /f "tokens=*" %%a in (File.txt) do set LastLine=%%a
echo %LastLine%
gateleys
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Re: Read the last line of a file

Post by gateleys »

The same site also had a post to find the line count using DOS. Here is the post -

Code: Select all

find /v /c "z z z z " filename

the /v tells it 'non-matching lines' and you give it some string which is almost surely not there.

The /c tells it 'line count only'.

gateleys
ravibabu
Participant
Posts: 39
Joined: Tue Feb 13, 2007 12:18 am
Location: vijayawada

Post by ravibabu »

Hay,

If you ant follow the steps...

!) Find the number of records in file.
2) take a last line of the file. mean ...line number = count.

then read the character..
Post Reply