Need unix/linux command

Hi,

When i ran the command as sar in linux box. i got a output like as below

[spt@scrbgcddkcph431 tools]$ sar
Linux 2.6.18-274.3.1.el5 (scrbgcddkcph431)      06/29/2012

12:00:01 AM       CPU     %user     %nice   %system   %iowait    %steal     %idle
12:10:01 AM       all           8.78       0.00      26.11       3.80         0.00        61.30
12:20:01 AM       all           3.09       0.00      5.12         1.13         0.00        90.65
12:30:01 AM       all           1.03       0.00      1.69         0.04         0.00         97.23

But i would like to convert from above output to mentioned below one.

Linux 2.6.18-274.3.1.el5 (scrbgcddkcph431)      06/29/2012

12:00:01       %user     %system   %iowait    %idle
12:10:01       8.78       26.11       3.80          61.30
12:20:01       3.09       5.12         1.13          90.65
12:30:01       1.03       1.69         0.04          97.23

Please advice on this.

$ awk '{$2=""; $3=""; print}' infile
 
$ sar | awk 'NR>2{$2=$3=""}1'
Linux 2.6.18-274.3.1.el5 (scrbgcddkcph431)      06/29/2012
12:00:01   %user %nice %system %iowait %steal %idle
12:10:01   8.78 0.00 26.11 3.80 0.00 61.30
12:20:01   3.09 0.00 5.12 1.13 0.00 90.65
12:30:01   1.03 0.00 1.69 0.04 0.00 97.23

Hi jayan and kamaraj..

Thank you for your's quick response.. But i would like proper alignment as well. Because i am going to store those entry into one file. then will read from that file in php ...

Please help on this

Checkout the command printf and if it does not work, show your tries please.

 
$ sar |nawk -v OFS="\t" 'NR>2{$2=$3=""}1'
Linux 2.6.18-274.3.1.el5 (scrbgcddkcph431)      06/29/2012
12:00:01                        %user   %nice   %system %iowait %steal  %idle
12:10:01                        8.78    0.00    26.11   3.80    0.00    61.30
12:20:01                        3.09    0.00    5.12    1.13    0.00    90.65
12:30:01                        1.03    0.00    1.69    0.04    0.00    97.23

 
 sar | awk 'NR>2{$2=$3=""}1' | column -t

Thank you Kamaraj... below metioned cmds also worked ...

sar | awk 'NR>2 {$2=$3=$5=$8="";}1' | tr -s '  ' '\t'

thanks once again

---------- Post updated at 07:10 AM ---------- Previous update was at 04:22 AM ----------

Hi one more doubt about sar command. could you please advice on this

nohup sar -u 10 $COUNT |  awk 'NR>2 {$2=$4=$7="";}1' | tr -s '  ' '\t' 2>/dev/null >sar.out &

i have execute above line from shell script .. but sar.out is created with ZERO bite size..

Help on that what is the problem here

@itkamaraj: when a moderator asks a user to show what effort they have made it is rude just to steam in and blurt out an answer to the question. You have been asked not to do this, on previous occasions.

Also, please change your user title. It's a form of signature, and we don't allow those. Thanks.

2 Likes