LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Need help in understanding File system utilization expression (https://www.linuxquestions.org/questions/linux-general-1/need-help-in-understanding-file-system-utilization-expression-4175576732/)

kverma1985 04-05-2016 09:24 AM

Need help in understanding File system utilization expression
 
Hi,

The below file system utilization check command is being used in one of the solution.

df -k | awk '$1~/^\/dev\//{keep="y"}NF==1{arg1==$1}NF==5{if(keep="y")print arg1,$0;keep="n"}NF==6{if(keep=="y")print;keep="n"}'

I need to understand how the above expression is working. I do understand that it is concatenates two lines into one if the file system utilization is broken into two lines. The rest I'm unable to understand.

rknichols 04-05-2016 01:27 PM

Quote:

Originally Posted by kverma1985 (Post 5526562)
Code:

df -k | awk '$1~/^\/dev\//{keep="y"}NF==1{arg1==$1}NF==5{if(keep="y")print arg1,$0;keep="n"}NF==6{if(keep=="y")print;keep="n"}'

The only other thing I see that doing is, in a rather convoluted way, suppressing the header line. Rewriting as multiple lines and adding comments:
Code:

$1~/^\/dev\//{keep="y"}                  # If the first field contains "/dev/" set keep to "y"
NF==1{arg1==$1}                          # If there is just 1 field, save it as the device path
NF==5{if(keep="y")print arg1,$0;keep="n"} # If 5 fields and "/dev/" was seen, print the device
                                          #  path and the current line
NF==6{if(keep=="y")print;keep="n"}'      # If 6 fields and "/dev/" present, print the line

It ignores any line without a contained "/dev/" string or a preceding "/dev/" string that was not already printed.

It's a rather complex substitute for
Code:

df -P -k | grep /dev/


All times are GMT -5. The time now is 04:48 AM.