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 7014179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:29:15+00:00 2026-05-27T22:29:15+00:00

Given this format: DISKGROUP NAME GB ALLOCATED GB USED GB FREE USABLE GB PCT

  • 0

Given this format:

DISKGROUP NAME    GB ALLOCATED         GB USED         GB FREE       USABLE GB PCT USED STATUS                          
-------------- --------------- --------------- --------------- --------------- -------- --------------------            
DISK_1             1,117.40          390.48          726.92          223.78    34.95 MOUNTED                         
DISK_2         1,117.40           65.97        1,051.43          386.04     5.90 MOUNTED   

With a single bash command how can I reliably get the value from GB FREE? The number of spaces between fields can very based on the field size, so I can’t specify a static number of spaces with cut. Is there a way to use spaces as delimiter, but have the number of spaces be a variable size?

Thanks for any ideas

  • 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-05-27T22:29:16+00:00Added an answer on May 27, 2026 at 10:29 pm

    You can use awk for this:

    awk 'BEGIN {print "GB FREE\n--------"} NR>2{print $4}' INPUT_FILE
    

    Explanation:

    1. We use awk's BEGIN statement to print the heading which is GB FREE and -------. This is because the heading in your input file has spaces in the titles. This can throw the awk script off.
    2. Second, we use awk's built-in variable NR which stores the line number. Since we don’t want line 1 and 2 to be printed, we keep a condition of NR>2. This way awk will skip the first two lines and start printing from line 3.
    3. In awk by default, the delimiter or Field separator is spaces (one or more). Since your file has that we don’t need to set the FS built-in variable. Each field separated by a space becomes a column and can be accessed using $ and column number. Since you want the GB FREE column which is 4, we do print $4.
    4. To keep more conditions, like printing only those lines where column 1 has DISK_2 we add another pattern statement. Using NR>2 && $1~/DISK_2/ ensures we don’t print lines 1 and 2 and look for lines where column 1 has DISK_2 in them and print the column 4 of those lines.

    Note: If you don’t really care about the heading part, you can shorten this one-liner to the following (depending on your requirement):

    awk 'NR>2{print $4}' INPUT_FILE
    

    or

    awk 'NR>2 && $1~/DISK_2/{print $4}' INPUT_FILE
    

    Test:

    [jaypal:~/Temp] cat file
    DISKGROUP NAME    GB ALLOCATED         GB USED         GB FREE       USABLE GB PCT USED STATUS                          
    -------------- --------------- --------------- --------------- --------------- -------- --------------------            
    DISK_1             1,117.40          390.48          726.92          223.78    34.95 MOUNTED                         
    DISK_2         1,117.40           65.97        1,051.43          386.04     5.90 MOUNTED   
    
    [jaypal:~/Temp] awk 'BEGIN {print "GB FREE\n--------"} NR>2{print $4}' file
    GB FREE
    --------
    726.92
    1,051.43
    

    To add filters as stated in the comments:

    [jaypal:~/Temp] awk 'BEGIN {print "GB FREE\n--------"} NR>2 && $1~/DISK_2/{print $4}' file
    GB FREE
    --------
    1,051.43
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this data set: ID Name City Birthyear 1 Egon Spengler New York 1957
Given this XML ... <ListBucketResult xmlns=http://s3.amazonaws.com/doc/2006-03-01/> <Name>public.rpmware.com</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> <Contents> <Key>0.dir</Key> <LastModified>2008-06-25T16:09:49.000Z</LastModified>
An absolute time is given in stored in this format: time = 000:03:07.447 How
Given this regex: ^((https?|ftp):(\/{2}))?(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3} (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|(((([a-zA-Z0-9]+)(\.)*?))(\.)([a-z]{2} |com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum){1}) Reformatted for readability: @^((https?|ftp):(\/{2}))? + // http://, https://,
Given this XML Schema snippet: <xs:element name=data> <xs:complexType> <xs:sequence> <xs:element name=param type=param minOccurs=0 maxOccurs=unbounded
Given a string in the following format (the Posterous API returns posts in this
Given this simplified data format: <a> <b> <c>C1</c> <d>D1</d> <e>E1</e> <f>don't select this one</f>
Right now I have double numba = 5212.6312 String.Format({0:C}, Convert.ToInt32(numba) ) This will give
Given this HTML: <ul id=topnav> <li id=topnav_galleries><a href=#>Galleries</a></li> <li id=topnav_information><a href=#>Information</a></li> </ul> And this
Given this XML, what XPath returns all elements whose prop attribute contains Foo (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.