Let say I have the program:
Calculate.py
Is there a unix command-line that counts the number of lines outputted from my program, Calculate.py?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityLet say I have the program:
Calculate.py
Is there a unix command-line that counts the number of lines outputted from my program, Calculate.py?
You can pipe the output in to wc
. You can use the -l
flag to count lines. Run the program normally and use a pipe to redirect to wc.
python Calculate.py | wc -l
Alternatively, you can redirect the output of your program to a file, say calc.out
, and run wc
on that file.
python Calculate.py > calc.out
wc -l calc.out
wc
. Mercifully this is easy (cut -f1 -d' '
), but the same isn't true for every command. There's something to be said for the Powershell approach of making the command line primitive an "object", rather than a text stream.
– shadowtalker
Nov 26 '18 at 19:42
object
s instead of String
s makes sense. At some point I'd like to dive deep into more command line tooling.
– Joshua Pinter
Nov 27 '18 at 2:13
Above communicate (wc -l) will count the empty lines too. so better to use below command which deletes the empty lines and count it
python Calculate.py |sed '/^$/d'| awk '{print NR}'| sort -nr| sed -n '1p'