home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 10
/
aminetcdnumber101996.iso
/
Aminet
/
util
/
cli
/
heads.lha
/
heads.lha
/
tail.rexx
< prev
Wrap
OS/2 REXX Batch file
|
1995-04-15
|
2KB
|
90 lines
/* tail.rexx emulates an enhanced version of UNIX tail
© Herbert Wollman April 15, 1995 */
CMD = ARG(1)
IF UPPER(CMD) == '-H' THEN
DO
SAY 'USAGE: tail [-Lines] [File] [OtherFiles]'
EXIT
END
C = 10
IF DATATYPE(WORD(CMD,1),WHOLE) & (LEFT(CMD,1) == '-') THEN
DO
PARSE VAR CMD PAT CMD
C = ABS(PAT)
END
WRDS = WORDS(CMD)
IF WRDS = 0 THEN
DO
M = 0
L = 1
A = READLN(STDIN)
DO WHILE ~EOF(STDIN)
B.L = A
L = L + 1
IF L > C THEN
DO
L = 1
M = 1
END
A = READLN(STDIN)
END
L = L - 1 + C * (L = 1)
H = 1 + L * M * (L < C)
DO WHILE H ~= L
SAY B.H
H = 1 + H * (H < C)
END
SAY B.L
EXIT
END
IF ~SHOW('LIBS:','rexxarp.library') THEN
CALL ADDLIB("rexxarplib.library",0,-30,0)
N = 0
J = 1
DO WHILE WORDS(CMD) > 0
IF LEFT(CMD,1) == '"' THEN
PARSE VAR CMD '"' PAT '"' CMD
ELSE
PARSE VAR CMD PAT CMD
CMD = STRIP(CMD)
CNT = FileList(PAT, F.J,'F')
J = J + (CNT > 0) /* If there were any matches, increment J */
N = N + CNT
END
J = J - (CNT > 0)
Q = 0
DO I = 1 TO J /* Loop over all the patterns */
DO K = 1 TO F.I.0 /* Loop over all the matches */
PAT = F.I.K
IF OPEN(FL,PAT,'READ') THEN
DO
IF Q > 0 THEN; SAY ''
Q = 1
IF N > 1 THEN; SAY PAT '==>'
M = 0
L = 1
A = READLN(FL)
DO WHILE ~EOF(FL)
B.L = A
L = L + 1
IF L > C THEN
DO
L = 1
M = 1
END
A = READLN(FL)
END
CALL CLOSE(FL)
L = L - 1 + C * (L = 1)
H = 1 + L * M * (L < C)
DO WHILE H ~= L
SAY B.H
H = 1 + H * (H < C)
END
SAY B.L
END
ELSE
SAY '== Unable to Open File' PAT '=='
END
END