Find the answer to your Linux question:
Results 1 to 3 of 3
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 ...
  1. #1
    Just Joined!
    Join Date
    Dec 2010
    Posts
    5

    Question Get a field value corresponding to another field value

    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 PERCENTAGE in a variable for a value of storage passed as variable

    i have tried the following without success like :


    Code:
    percentage='awk -vx="$defaultStorage"  '{FS=OFS=" "}$1==x{print $2}1' file.dat
    Please guide me on this..

    Thanks in advance

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Something like this:

    Code:
    defaultStorage="storage_02"
    
    percentage=$(awk -vx="$defaultStorage" '$1 ~ x{print $2}' file.dat)

  3. #3
    Just Joined!
    Join Date
    Dec 2010
    Posts
    5
    Thank you...

Posting Permissions

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