Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8552445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:25:31+00:00 2026-06-11T14:25:31+00:00

The so-far expertly crafted script iostat -p -x 1 2| grep $1[^[:digit:]] | awk

  • 0

The so-far expertly crafted script

iostat -p -x 1 2| grep $1[^[:digit:]] | awk '{print $9}'

will return two lines:

0.16
0.00

because iostat is taking two samples. But you already knew that. My question is since you and I both know it will be exactly two lines every time, how I pick out exactly the second?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:25:32+00:00Added an answer on June 11, 2026 at 2:25 pm

    Add NR==2 before {print $9} to tell awk to match record 2.

    For example, on my system,

    $ iostat -x /dev/sda 1 2 | grep sda
    
    $ iostat -x /dev/sda 1 2 | grep sda | awk 'NR==1 {print $9}'
    
    $ iostat -x /dev/sda 1 2 | grep sda | awk 'NR==2 {print $9}'
    

    produced

    sda               0.11     1.04    2.00    1.28   125.95    63.24   115.15     0.07   21.04    4.66   46.60   2.36   0.78
    sda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
    0.07
    0.00
    

    where that “0.00” line is the result of the third command.

    Additional note: It isn’t necessary to run a separate grep command, as awk can match text. However, the awk script then needs an index variable. The first of the following examples is a simple grep to show what awk works on. The next two examples are straightforward awk code that has a match test to increment an index and another match test plus index test to print. The last example shows how to get rid of extra appearances of the match expression. Note, in these examples I replaced print $9 with print for clarity, and $1[^[:digit:]] with sda[^0-9]. Here are the examples which do the matching in awk instead of in grep:

    $ iostat -p -x 1 2  | grep 'sda '
    sda               0.11     1.04    2.00    1.28   125.70    63.16   115.09     0.07   21.04    4.66   46.57   2.36   0.78
    sda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
    
    $ iostat -p -x 1 2  | awk '/sda[^0-9]/ {++t} t==1 && /sda[^0-9]/ {print}'
    sda               0.11     1.04    2.00    1.28   125.70    63.16   115.09     0.07   21.04    4.66   46.57   2.36   0.78
    
    $ iostat -p -x 1 2  | awk '/sda[^0-9]/ {++t} t==2 && /sda[^0-9]/ {print}'
    sda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
    
    $ iostat -p -x 1 4  | awk '/sda[^0-9]/ && t++ && t==2 {print}'
    sda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So far I only found two ways: throw exception play nothing ad.2. Pretty recent
Far I've found that giving the iframe a background colour will alter the timeline
So far I know two ways to pass php variables to javascript. One is
As far as I know (which is very little) , there are two ways,
As far as I know, Google will index a page if it meets at
As far as I know, ./configure script is generated with GNU Autoconf . I
So far, to print out the values of pointers (addresses) I have, (correctly or
Far as best practices are concerned, which is better: public void SomeMethod(string str) {
as far as I know both 2012-07-04T17:30:52+00:00 and 2012-07-04T17:30:52Z are dates in iso8601 format
As far as i remember while installing ubuntu,the installer didn't ask me for the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.