×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

awk to grep and print output

awk to grep and print output

awk to grep and print output

(OP)
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

RE: awk to grep and print output



Check out this post: http://www.tek-tips.com/viewthread.cfm?qid=1709827
3eyes

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

RE: awk to grep and print output

(OP)
[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[i]]}; printf "\n"}
{for(i in arr){ k=arr[i]; 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

RE: awk to grep and print output

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close