Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 11-10-2016, 03:06 PM   #1
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

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


Help me out in this regard

Thank you!
Old 11-10-2016, 03:30 PM   #2
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,788
Blog Entries: 13

Rep: Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831
Member Response


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:
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, 10:41 PM   #3
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,976

Rep: Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181Reputation: 3181
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, 01:11 PM   #4
Senior Member
Registered: Dec 2011
Location: Simplicity
Posts: 2,453

Rep: Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062
Maybe you only want to see local disks?
The all start with a / usually /dev/
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
df -kP | awk '($1~/^\/dev\// && $5>80) {print $1,$5,$6}'


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 10:04 PM
turning awk command line entries into awk scripts tabbyagirl Linux - Newbie 5 08-22-2013 12:46 AM
Help needed with awk khaos83 Linux - General 4 02-12-2009 01:21 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM
Sed/Awk command help needed. farmerjoe Programming 3 03-02-2005 11:13 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:24 PM.

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