LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-24-2009, 06:05 AM   #1
MasterOfTheWind
Member
 
Registered: Jul 2004
Distribution: Arch, Debian sid, Kubuntu, Slackware 11
Posts: 324

Rep: Reputation: 30
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
 
Old 05-24-2009, 07:15 AM   #2
lugoteehalt
Senior Member
 
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215
Blog Entries: 2

Rep: Reputation: 49
Err, doesn't grep -v filth mean 'find everything except filth'??
 
Old 05-24-2009, 07:29 AM   #3
MasterOfTheWind
Member
 
Registered: Jul 2004
Distribution: Arch, Debian sid, Kubuntu, Slackware 11
Posts: 324

Original Poster
Rep: Reputation: 30
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.
 
Old 05-24-2009, 07:33 AM   #4
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Is that what you mean?
Quote:
iostat -d 1 | sed -u -e 's/sda1/Backup:/g'
edit: I didn't see your second post.

Last edited by sycamorex; 05-24-2009 at 07:35 AM.
 
Old 05-24-2009, 07:39 AM   #5
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Quote:
iostat -d 1 | sed -u -e 's/sda1/Backup:/g' | grep -vw sd.
???
 
Old 05-24-2009, 07:46 AM   #6
MasterOfTheWind
Member
 
Registered: Jul 2004
Distribution: Arch, Debian sid, Kubuntu, Slackware 11
Posts: 324

Original Poster
Rep: Reputation: 30
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?
 
Old 05-24-2009, 07:50 AM   #7
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
Quote:
Originally Posted by MasterOfTheWind View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why doesn't tee $(tty) produce output on the current terminal? openSauce Linux - Newbie 12 01-18-2016 12:25 PM
LXer: Bash One-Liner Script To Produce Somewhat-Fancy Output Of Who's On Your Linux O LXer Syndicated Linux News 0 11-19-2008 01:40 AM
Sed and Awk Gins Programming 7 04-19-2006 10:32 AM
xterm will not produce output with -lf parameter jarobman Linux - General 2 03-06-2005 02:12 AM
Running a program inside my QT application does not produce needed output files??? keos Programming 0 02-22-2004 11:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration