Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Have @LINE return the last line of a file

Aug
2,815
147
I'm currently using a UDF to obtain the last line of a file;

Code:
function LastLine=`%@line[%1,%@lines[%1]]`

In the @WORD function,
you can specify the rightmost word by setting n to -0.

I'd like to suggest the following for the @LINE function;
Code:
set LastLine=%@line[%temp\QResults.txt,-0]
...to obtain the last line in a file.

Ref: @WORD TCC internal variable function
Ref: @LINE TCC internal variable function

Joe
 
That's a good suggestion for @LINE. For the time being, you could roll your own (with no safeguards).

Code:
v:\> function nthline `%@line[%1,%@if[%@left[1,%2] == -,%@eval[%@lines[%1]+%2],%2]]`

v:\> (do i=1 to 10 (echo %i)) > 1to10.txt

v:\> echo %@nthline[1to10.txt,0]
1

v:\> echo %@nthline[1to10.txt,1]
2

v:\> echo %@nthline[1to10.txt,-0]
10

v:\> echo %@nthline[1to10.txt,-1]
9
 
Back
Top