LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-05-2016, 09:24 AM   #1
kverma1985
LQ Newbie
 
Registered: Sep 2012
Posts: 2

Rep: Reputation: Disabled
Exclamation 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.
 
Old 04-05-2016, 01:27 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by kverma1985 View Post
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/
 
2 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Understanding File System rupeshkp728 Linux - General 3 07-17-2012 09:48 PM
[SOLVED] need help understanding this bash expression emanresu Programming 4 04-14-2012 12:03 PM
need help understanding this expression emanresu Linux - General 2 04-11-2012 05:41 PM
Root file system shows 100% percent utilization simplyrahul Linux - Software 1 11-26-2004 10:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration