LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   AWK/Sed do not produce any output (http://www.linuxquestions.org/questions/linux-newbie-8/awk-sed-do-not-produce-any-output-728147/)

MasterOfTheWind 05-24-2009 06:05 AM

AWK/Sed do not produce any output
 
Hi, everybody!

What I am trying to do is to take continuous output from a program called iostat and replace each occurence of "sda1" with "Backup".

I have tried to do the following

Code:

iostat -d 1 | grep -vw sd. | awk '{gsub(/sda1/,"Backup:");print}'

AND

iostat -d 1 | grep -vw sd. | sed -e 's/sda1/Backup:/g'


Nonetheless I do not get any output whatsoever. What am I doing wrong? Do I have to specify somewhere that awk/sed should flush output after each line or something?

Thanks in advance ;)

lugoteehalt 05-24-2009 07:15 AM

Err, doesn't grep -v filth mean 'find everything except filth'??

MasterOfTheWind 05-24-2009 07:29 AM

It does, I am filtering away all lines containing regexp "sd."

There is plenty of output left after grep-ing:

Code:

Device:            tps  Blk_read/s  Blk_wrtn/s  Blk_read  Blk_wrtn
sda1              0.00        0.00        0.00          0          0
sdb1              0.00        0.00        0.00          0          0
sdb2              0.00        0.00        0.00          0          0
sdb3              0.00        0.00        0.00          0          0
sdb4              0.00        0.00        0.00          0          0
sdc1              2.00      256.00        0.00        256          0
sdd1              0.00        0.00        0.00          0          0

Oh yes, and something crucial I forgot to mention in my first post: The point of the whole operation is is that "iostat" is producing a new chunk of output every second until I explicitly interrupt it.

It appears that it is there the problem lies, because if I run "iostat" only a single time (so that it outputs a paragraph of data and exits), then all works properly.

sycamorex 05-24-2009 07:33 AM

Is that what you mean?
Quote:

iostat -d 1 | sed -u -e 's/sda1/Backup:/g'
edit: I didn't see your second post.

sycamorex 05-24-2009 07:39 AM

Quote:

iostat -d 1 | sed -u -e 's/sda1/Backup:/g' | grep -vw sd.
???

MasterOfTheWind 05-24-2009 07:46 AM

Yes, thank you, that worked!

I have now looked up the "-u" switch for sed, but I am still unsure though as to why it makes any difference which of grep and sed commands comes first?

sycamorex 05-24-2009 07:50 AM

Quote:

Originally Posted by MasterOfTheWind (Post 3551017)
Yes, thank you, that worked!

I have now looked up the "-u" switch for sed, but I am still unsure though as to why it makes any difference which of grep and sed commands comes first?

To be honest, it's puzzling me as well. Hopefully, someone will provide some explanation.


All times are GMT -5. The time now is 05:25 PM.