2

I'm trying to count the lines from a command and I'd also like to see the lines as they go by. My initial thought was to use the tee command:

complicated_command | tee - | wc -l

But that simply doubles the line count using GNU tee or copies output to a file named - on Solaris.

7
  • Ah. My searches failed to find that question. Feb 28, 2009 at 0:11
  • Searching is never perfect, especially with this sort of command.
    – Adam Davis
    Feb 28, 2009 at 0:17
  • Now we have a new set of keywords. ;-) Feb 28, 2009 at 0:18
  • I found it because I have the accepted answer on that one. Feb 28, 2009 at 0:19
  • google site:stackoverflow.com <yourstuff> and it will find u everything :p Feb 28, 2009 at 0:22

2 Answers 2

7
complicated_command | tee /dev/tty | wc -l

But keep in mind that if you put it in a script and redirect the output, it won't do what you expect.

2
  • Thanks. I wonder why I didn't know that /dev/tty points to my terminal name. Glad I asked since that reduces my code a bit. Feb 28, 2009 at 0:26
  • Yeah, /dev/tty is an alias for your current tty. It's very useful like that. Feb 28, 2009 at 1:06
1

The solution is to tee to the console directly as opposed to STDOUT:

tty=`tty`
complicated_command | tee $tty | wc -l
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.