Welcome!

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

SignUp Now!

LC - Line Counter

May
366
4
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
}
 
Back
Top