Hi
I have an output of sar
command which is as follows:
10:22:18 bread/s lread/s %rcache bwrit/s lwrit/s %wcache pread/s pwrit/s
10:23:18 0 398 100 5 13 64 0 0
10:24:18 0 332 100 5 15 65 0 0
10:25:18 0 301 100 6 17 67 0 0
10:26:18 0 309 100 5 16 69 1 0
10:27:18 0 178 100 5 13 61 0 0
10:28:18 0 118 100 14 17 16 0 0
10:29:18 0 189 100 10 16 35 0 0
10:30:18 0 249 100 5 20 74 0 0
10:31:18 0 147 100 14 21 32 1 0
10:32:18 0 325 100 6 14 59 0 0
10:33:18 0 570 100 6 15 60 0 0
10:34:18 0 734 100 6 16 62 0 0
10:35:18 0 704 100 6 22 70 0 0
10:36:18 0 718 100 6 15 59 0 0
10:37:18 0 794 100 6 15 59 0 0
10:38:18 0 796 100 5 12 57 0 0
10:39:18 0 739 100 5 11 51 0 0
10:40:18 0 714 100 6 17 65 0 0
10:41:18 0 1281 100 18 21 17 0 0
10:42:18 0 700 100 6 17 64 1 0
10:43:18 0 720 100 5 14 60 0 0
10:44:18 0 846 100 6 15 60 0 0
10:45:18 0 799 100 6 19 67 0 0
10:46:18 0 663 100 6 15 62 0 0
10:47:18 0 710 100 6 17 64 1 0
10:48:18 0 642 100 6 12 53 0 0
10:49:18 0 713 100 6 13 56 0 0
10:50:18 0 746 100 6 18 69 0 0
10:51:18 0 1241 100 17 22 23 0 0
10:52:18 0 773 100 6 18 68 1 0
Average 0 605 100 7 16 56 0 0
and I want to extract the 1st, 4th and 7th column but adding before the hour column another column with 1, 2, 3, and so on like:
1
2
3
4
5
6
7
I have try to use the following piece of code:
cat sarb.out | \
awk 'BEGIN {LINE=1; printf "#Spl Date %%rcache %%wcache\n"; }
{ if ( NF == 9 ) {
if($1 != "Average") DATE=$1
if($1 == "Average") {
printf "%4d %s %7d %7d\n", LINE, DATE, $4, $7
LINE++}
}
}'
but my output is only one line.
please can you help
---------- Post updated at 12:13 PM ---------- Previous update was at 11:37 AM ----------
my expected output should be:
10:22:18 %rcache %wcache
1 10:23:18 100 64
2 10:24:18 100 65
3 10:25:18 100 67
4 10:26:18 100 69
5 10:27:18 100 61
6 10:28:18 100 16
7 10:29:18 100 35
8 10:30:18 100 74
9 10:31:18 100 32
10 10:32:18 100 59