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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-24-2009, 06:05 AM
|
#1
|
|
Member
Registered: Jul 2004
Distribution: Arch, Debian sid, Kubuntu, Slackware 11
Posts: 324
Rep:
|
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 
|
|
|
|
05-24-2009, 07:15 AM
|
#2
|
|
Senior Member
Registered: Sep 2003
Location: UK
Distribution: Debian
Posts: 1,215
Rep:
|
Err, doesn't grep -v filth mean 'find everything except filth'??
|
|
|
|
05-24-2009, 07:29 AM
|
#3
|
|
Member
Registered: Jul 2004
Distribution: Arch, Debian sid, Kubuntu, Slackware 11
Posts: 324
Original Poster
Rep:
|
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.
|
|
|
|
05-24-2009, 07:33 AM
|
#4
|
|
LQ Veteran
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,089
|
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.
|
|
|
|
05-24-2009, 07:39 AM
|
#5
|
|
LQ Veteran
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,089
|
Quote:
|
iostat -d 1 | sed -u -e 's/sda1/Backup:/g' | grep -vw sd.
|
???
|
|
|
|
05-24-2009, 07:46 AM
|
#6
|
|
Member
Registered: Jul 2004
Distribution: Arch, Debian sid, Kubuntu, Slackware 11
Posts: 324
Original Poster
Rep:
|
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?
|
|
|
|
05-24-2009, 07:50 AM
|
#7
|
|
LQ Veteran
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,089
|
Quote:
Originally Posted by MasterOfTheWind
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:58 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|