LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-10-2016, 04:06 PM   #1
Owais.Ahmad
LQ Newbie
 
Registered: Jul 2012
Posts: 10

Rep: Reputation: Disabled
Post AWK Command Help Needed


Hello All,

I have following lines and i want an output displaying the disc space greater than 80%.

df -kh
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk1 465Gi 229Gi 235Gi 50% 909633 4294057646 0% /
devfs 182Ki 182Ki 0Bi 100% 628 0 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% 0 0 100% /net
map auto_home 0Bi 0Bi 0Bi 100% 0 0 100% /home

I'm using the AWK Command so extract the column so checked can be applied on its output but it is giving me the following lines,

Owaiss-MBP:Scripting $ awk '{print $9}' DF.rtf








Mounted
/\
/dev\
100%
100%
Owaiss-MBP:Scripting $ awk '{print $8}' DF.rtf







-kh\
%iused
0%
100%
0
0


Help me out in this regard

Thank you!
 
Old 11-10-2016, 04:30 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,102
Blog Entries: 10

Rep: Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524Reputation: 1524
Member Response

Hi,

Awk is giving you exactly what you've asked for. Column 9 and then column 8. The issues are that the lines of input have different counts of columns.

To print the last field or column you use the notation:
Code:
awk '{print $NF}'
This is assuming that the lines input are already filtered to only show resources in excess of 80%.
 
1 members found this post helpful.
Old 11-10-2016, 11:41 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,253

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
Firstly, please use [code/][code] tags around your code and data to make it clearer and preserve formatting.

I am a little concerned at seeing we are using an 'rtf' type file, was it created ion a Windows machine? I only ask as it may skew the results.

As above, when columns vary you will nede a way of identifying the required column from a specific line or as shown if always the last item is required you can use the NF variable.

Maybe you could explain how you came by your data? ie. what have you already used on the original output to get the current output?
 
Old 11-11-2016, 02:11 PM   #4
MadeInGermany
Member
 
Registered: Dec 2011
Posts: 198

Rep: Reputation: 76
Maybe you only want to see local disks?
The all start with a / usually /dev/
Code:
df -kP | awk '($1~/^\/dev\//) {print $1,$5,$6}'
If you want to only list the disks that are over 80% used, then add another condition into the implicit if clause
Code:
df -kP | awk '($1~/^\/dev\// && $5>80) {print $1,$5,$6}'
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Needed with AWK/CUT maddyfreaks Linux - Newbie 3 01-20-2014 11:04 PM
turning awk command line entries into awk scripts tabbyagirl Linux - Newbie 5 08-22-2013 01:46 AM
Help needed with awk khaos83 Linux - General 4 02-12-2009 02:21 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 05:11 PM
Sed/Awk command help needed. farmerjoe Programming 3 03-02-2005 12:13 PM


All times are GMT -5. The time now is 10:54 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration