LC - Line Counter

For some reason I find I do this quite a bit. I want to know how many lines are in a file or pipe. So this simple script effectively does what "wc -l" does in unix.

You can provide a filename or send via a pipe. I thought one of the cool things about this if you give it a filename, it just pipes it to itself. Ok, not the fanciest recursion, but I thought it was neat.

Code:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: lc
::
:: Simple function that counts the number of lines in the file
:: given or via a piped output
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
lc {
    set lcLineCounter=0

    iff exist %1 then
        :: Process provided file
        type %1 | lc
    else
        :: Process pipe
        for %i in (@con) set lcLineCounter=%@Inc[lcLineCounter]
        echo %lcLineCounter
    endiff

    unset lcLineCounter
}
 
Thread starter Similar threads Forum Replies Date
Fross T&T - Library Functions 0