printing space after a record in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting printing space after a record in awk
# 1  
Old 04-12-2010
printing space after a record in awk

friends,
I am running iostat command in linux. Following is the output

Code:
iostat -d
Linux 2.6.18-128.el5 (btovm725.ind.hp.com)      04/16/2010

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda              21.49         5.32       255.61    2871221  138010414
sda1              0.00         0.00         0.00       2172         38
sda2              0.00         0.00         0.00       1727        144
sda3             21.49         5.31       255.61    2866762  138010232
fd0               0.00         0.00         0.00         88          0

In order to eliminate all unnecessary values, this is the script i am using

Code:
iostat -d  2 2|  awk ' /sd[a-z]+[^0-9]/ || /hd[a-z]+[^0-9]/ || /fd[0-9]+/'

and this is the output

Code:
sda              21.49         5.32       255.64    2871221  138035798
fd0               0.00         0.00         0.00         88          0
sda               0.00         0.00         0.00          0          0
fd0               0.00         0.00         0.00          0          0

i want to insert a blank space after each iteration. The way i want my output to be is as follows -->

Code:
sda              21.49         5.32       255.64    2871221  138035798
fd0               0.00         0.00         0.00         88          0

sda              21.49         5.32       255.64    2871221  138035798
fd0               0.00         0.00         0.00         88          0

Pls can u guide me on how to achieve this

Last edited by Franklin52; 04-12-2010 at 08:16 AM.. Reason: Please use code tags!
# 2  
Old 04-12-2010
This perhaps:
Code:
iostat -d  2 2 | egrep "^sd[a-z]+ |^[fh]d"

or
Code:
iostat -d  2 2 | awk '/^[a-z]/&&!/^sd[a-z]+[0-9]/'

# 3  
Old 04-12-2010
sorry boss. no change in result.
Code:
iostat -d  2 2 |egrep "^sd[a-z]+ |^[fh]d"
sda              21.55         5.30       256.23    2871221  138684078
fd0               0.00         0.00         0.00         88          0
sda               0.00         0.00         0.00          0          0
fd0               0.00         0.00         0.00          0          0

i want a space to appear after the first iteration.
# 4  
Old 04-12-2010
Sorry, I misread your question. Something like this?
Code:
awk ' /sd[a-z]+[^0-9]/ || /hd[a-z]+[^0-9]/ || /fd[0-9]+/ || !NF&&NR>2'

# 5  
Old 04-12-2010
Code:
iostat -d  2 2|  awk ' /sd[a-z]+[^0-9]/ || /hd[a-z]+[^0-9]/ || /fd[0-9]+/ || !NF'

sda              21.62         5.29       257.11    2871221  139644510
fd0               0.00         0.00         0.00         88          0

sda               0.00         0.00         0.00          0          0
fd0               0.00         0.00         0.00          0          0

love u buddy. working like charm

Can u pls tell me the logic of the last line. how is achieving the desired result

Last edited by achak01; 04-12-2010 at 08:59 AM.. Reason: understanding of code
# 6  
Old 04-12-2010
Code:
iostat -d 2 2 | sed -n '/^[Device|Linux]/!{p}'



cheers,
Devaraj Takhellambam
# 7  
Old 04-12-2010
@scrutinizer.

Your script is working like charm.

i am still unable to understand the logic behind
Code:
iostat -d 2 2 awk ' /sd[a-z]+[^0-9]/ || /hd[a-z]+[^0-9]/ || /fd[0-9]+/ || !NF&&NR>2'

i just need to understand the significance of the last line i.e !NF.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help in printing records where there is a 'header' in the first record ???

Hi, I have a backup report that unfortunately has some kind of hanging indent thing where the first line contains one column more than the others I managed to get the output that I wanted using awk, but just wanting to know if there is short way of doing it using the same awk Below is what... (2 Replies)
Discussion started by: newbie_01
2 Replies

2. Shell Programming and Scripting

Selective printing based on matched record

Hi, I have file with thousands of lines somewhat similar to the below 6 lines 06MXXXXXXXXXXXXXXXX 0328 003529 J27300022 MICROSOFT *MSN 06<1 000000001344392 JPN151-85830 MSBILL.INFO F 06<A17087454000328651551 MSBILL.INFO ... (16 Replies)
Discussion started by: dsid
16 Replies

3. Shell Programming and Scripting

How to compare current record,with next and previous record in awk without using array?

Hi! all can any one tell me how to compare current record of column with next and previous record in awk without using array my case is like this input.txt 0 32 1 26 2 27 3 34 4 26 5 25 6 24 9 23 0 32 1 28 2 15 3 26 4 24 (7 Replies)
Discussion started by: Dona Clara
7 Replies

4. Shell Programming and Scripting

How to remove space from each record in file?

Hi , I want to remove space from each record in one file My file is like BUD, BDL ABC, DDD, ABC ABC, DDD, DDD, KKK The o/p should be BUD,BDL ABC,DDD,ABC ABC,DDD,DDD,KKK Can any one help me regarding this? (9 Replies)
Discussion started by: jagdishrout
9 Replies

5. Shell Programming and Scripting

printing lines before and after a record

Hello Everyone, I want to print out the records after and before a certain record. I am able to figure out how to print that particular record but not the ones before and after. Looking for some advice Thank you (6 Replies)
Discussion started by: danish0909
6 Replies

6. UNIX for Dummies Questions & Answers

awk script printing each record twice

i have a find command piped to an awk script, I'm expecting it printing the matching record one time but it's doing it twice: the following is my code: find directoryname | awk 'BEGIN { FS="/" } /.*\.$/ || /.*\.$/ { printf "%s/%s\n", $(NF-1), $NF } it gave me the correct output, but just... (2 Replies)
Discussion started by: ymc1g11
2 Replies

7. Shell Programming and Scripting

Unable to read the first space of a record in while loop

I have a loop like while read i do echo "$i" . . . done < tms.txt The tms.txt contians data like 2008-02-03 00:00:00 <space>00:00:00 . . . 2010-02-03 10:54:32 (2 Replies)
Discussion started by: machomaddy
2 Replies

8. UNIX for Dummies Questions & Answers

syntax for counting & printing record count

Hi I have a complex script which outputs a text file for loading into a db. I now need to enhance this script do that I can issue an ‘lp' command to show the count of the number of records in this file. Can anybody give me the necessary syntax ? (2 Replies)
Discussion started by: malts18
2 Replies

9. Shell Programming and Scripting

Replace comma by space for specified field in record

Hi, i want to replace comma by space for specified field in record, i mean i want to replace the commas in the 4th field by space. and rest all is same throught the record. the record is 16458,99,001,"RIMOUSKI, QC",418,"N",7,EST,EDT,902 16458,99,002,"CHANDLER,... (5 Replies)
Discussion started by: raghavendra.cse
5 Replies

10. Shell Programming and Scripting

need to space fill a 2060 byte record

Calling all experts: When I ftp from Mainframe to unix server, the ftp message says fixed length 2060, but i lose trailing spaces. I tried a solution i found here, awk ' { printf("%-2060s\n",$0) } ' fname1 > fname2 works for small records but, err msg: string too long, for long records ... (1 Reply)
Discussion started by: JohnMario
1 Replies
Login or Register to Ask a Question