Consultor Eletrônico



Kbase P50544: How to read the last line from a text file using tail ?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   12/30/2003
Status: Unverified

GOAL:

How to read the last line from a text file using tail ?

FIX:

Progress does not have utility/function to achieve/fullfill this task directly.

The following example is from Windows, it can be run on UNIX after changing the path's as well.

DEF VAR t AS CHAR NO-UNDO.
DEF STREAM s.

OS-COMMAND SILENT ("d:\tl.cmd").
INPUT STREAM s FROM d:\lastline.txt.
IMPORT STREAM s UNFORMATTED t.
INPUT STREAM s CLOSE.

MESSAGE t VIEW-AS ALERT-BOX.

The "t" variable contains content of the last line.

"tl.cmd" is a windows batch which contains 1 line

tail -1 "textfile" > d:\lastline.txt