Find the answer to your Linux question:
Results 1 to 5 of 5
Hi All, i am new to scripting i have a file : file.dat with following data Code: STORAGE PERCENTAGE FLAG: /storage_01 64% 0 /storage_02 17% 1 /storage_03 10% 0 /storage_04 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2010
    Posts
    5

    Question Get min from a column


    Hi All,

    i am new to scripting

    i have a file : file.dat with following data


    Code:
    STORAGE PERCENTAGE FLAG:
    /storage_01 64% 0
    /storage_02 17% 1
    /storage_03 10% 0
    /storage_04 50% 1
    I need to get the value of STORAGE from those with FLAG=0 and which has the min PERCENTAGE

    Please guide me on this..

    Thanks in advance

  2. #2
    Just Joined! barriehie's Avatar
    Join Date
    Apr 2008
    Location
    The Desert!
    Posts
    85
    Quote Originally Posted by kichoo View Post
    Hi All,

    i am new to scripting

    i have a file : file.dat with following data


    Code:
    STORAGE PERCENTAGE FLAG:
    /storage_01 64% 0
    /storage_02 17% 1
    /storage_03 10% 0
    /storage_04 50% 1
    I need to get the value of STORAGE from those with FLAG=0 and which has the min PERCENTAGE

    Please guide me on this..

    Thanks in advance
    Try this:
    Code:
    gawk '{ if($3~/0$/) { print $3, $2, $1 } }' ./file.dat > ./file.almost && sort -g ./file.almost > ./file.sorted && read < ./file.sorted && echo $REPLY | gawk '{ print $3, $2, $1 }' && rm ./file.almost && rm ./file.sorted

  3. #3
    Just Joined!
    Join Date
    Dec 2010
    Posts
    5
    Hi Barriehie,

    thank you so much..

    Can you please explain me the code?

    I am a newbie here....

    thanks a lot

  4. #4
    Just Joined!
    Join Date
    Dec 2010
    Posts
    5
    and also can you let me know how can i get the STORAGE value deried from this in a variable?

  5. #5
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Quote Originally Posted by kichoo View Post
    and also can you let me know how can i get the STORAGE value deried from this in a variable?
    Code:
    storagename=$(awk '
    NR==1{min=100;next}
    $3==0 && int($2)<min{min=int($2); s=$1}
    END{print s}' file)
    The solution is also given in this forum:

    Get min from a column conditionally - The UNIX and Linux Forums

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •