Operating System - Linux
1753923 Members
8136 Online
108810 Solutions
New Discussion юеВ

strange output to file behaviour.

 
SOLVED
Go to solution
Mark McDonald_2
Trusted Contributor

strange output to file behaviour.

Hi All

The following commands work as I expect them to:

free >> free1.out
free | grep "ers/c" >> free2.out
free -s 5 >> free3.out

The last command continually adds to the file.

BUT

This command will not update the output file:

free -s 5 | grep "ers/c" >> free4.out

It displays to the screen ok, but I am unable to redirect it to a file. Why not?
2 REPLIES 2
Steven Schweda
Honored Contributor
Solution

Re: strange output to file behaviour.

> [...] Why not?

Perhaps because the fancy-shmancy GNU "grep"
is too clever by half:

debi# uname -a
Linux debi 2.6.26-2-mckinley #1 SMP Fri Mar 27 05:13:51 UTC 2009 ia64 GNU/Linux

debi# date ; free -s 5 | grep 'ers/c' | cat ; date
Wed Jun 17 23:29:10 CDT 2009
^C
Wed Jun 17 23:29:25 CDT 2009

debi# date ; free -s 5 | grep --line-buffered 'ers/c' | cat ; date
Wed Jun 17 23:29:46 CDT 2009
-/+ buffers/cache: 184816 16495696
-/+ buffers/cache: 188544 16491968
-/+ buffers/cache: 187040 16493472
^C
Wed Jun 17 23:29:57 CDT 2009
Steven Schweda
Honored Contributor

Re: strange output to file behaviour.

> This command will not update the output file:

Check back again tomorrow. (Could be a
pretty big buffer.)