Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk to grep and print output 1

Status
Not open for further replies.

grapes12

Technical User
Mar 2, 2010
124
ZA
I have the following file which i need to extract only certain data from
Code:
                   extended device statistics
    r/s    w/s   kr/s   kw/s wait actv wsvc_t asvc_t  %w  %b device
    3.4    5.9  399.8  144.0  0.0  0.6    0.0   64.4   0  11 sd0
    0.4    3.3    5.0   33.0  0.0  0.1    0.0   19.9   0   1 sd1
    0.4    3.3    4.6   33.0  0.0  0.1    0.0   20.1   0   2 sd2
    3.6    6.1  417.1  144.0  0.0  0.1    0.0   13.6   0   3 sd3

I need to extract and print column 3,4,8,10,11
file name is sun8_iostat_13.04.17.0900.dat

asssistance will be much appreciated
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
[dazed]Evening tried link supplied by LKB but no joy
here is what I tried
{code}
vi iostat.ksh
"iostat.ksh" 13 lines, 313 characters
awk -F'|' -v fields="11,3,4,8,10" '
BEGIN{
#header array
h[1]="r/s";
h[2]="w/s";
h[3]="kr/s";
h[4]="kw/s";
h[5]="wait";
h[6]="actv";
h[7]="wsvc_t";
h[8]="asvc_t";
h[9]="%w";
h[10]="%b";
h[11]="device";
n=split(fields,arr,",");
print "fields="fields;
for(i in arr){printf "%s;",h[arr]}; printf "\n"}
{for(i in arr){ k=arr; printf "%s;",$k} printf "\n"}
' sun8_iostat_13.04.17.0800.dat
{/code}

tried running script here is output
{code}
./iostat.ksh
fields=11,3,4,8,10
asvc_t;%b;device;kr/s;kw/s;
;;;;;
;;;;;
;;;;;
;;;;;
;;;;;
;;;;;
;;;;;
;;;;;
;;;;;
;;;;;
;;;;;
;;;;;
;;;;;
;;;;;
;;;;;
{/code}

now i am truly confused, help will be much appreciated
 
Why not simply this ?
Code:
awk 'NR>1{print $11,$3,$4,$8,$10}' sun8_iostat_13.04.17.0800.dat

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks that worked like a dream.
BUT would it be possible to just select a certain device and its data from the file
e.g sd1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top