1

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.

Jon 'links in bio' Ericson
  • 20,880
  • 12
  • 98
  • 148

2 Answers2

6
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.

Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
1

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

tty=`tty`
complicated_command | tee $tty | wc -l
Jon 'links in bio' Ericson
  • 20,880
  • 12
  • 98
  • 148