how to retrieve only the Use% value from df command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to retrieve only the Use% value from df command
# 1  
Old 09-18-2008
how to retrieve only the Use% value from df command

when I do a df -k for a particular mount i get the result like this

Filesystem 1K-blocks Used Available Use% Mounted on
/dev/ 4128448 3527496 391240 91% /

I need to extract the value 91 from this and use it in my script in an if condition. How will i do it Please advice.
# 2  
Old 09-18-2008
Code:
df -k | awk -F " |%" '/dev/{print $5}'

Regards
# 3  
Old 09-18-2008
Franklin
I tried this one but its not working
its not returning anything
# 4  
Old 09-18-2008
this should work
Quote:
df -k|awk '/\/dev\//{printf("%d",$4);}'
# 5  
Old 09-18-2008

Code:
df | awk '/\/dev\//{printf("%d\n",$4)}'

Or:

Code:
df | awk '/\/dev\//{print $4}'

Or:

Code:
df | awk 'NR > 1 {print $4}'

# 6  
Old 09-19-2008
aah!! johnson the final one works good for me
I am able to get the value using df -k / | awk 'NR > 1 {print $4}' | cut -d "%" -f 1

but is there a more dynamic option than hardcoding $4 ...
thanks for all franklin vidyadhar johnson...
# 7  
Old 09-19-2008
Quote:
Originally Posted by codeman007
aah!! johnson the final one works good for me
I am able to get the value using df -k / | awk 'NR > 1 {print $4}' | cut -d "%" -f 1

You don't need cut; awk can remove the percent sign:

Code:
df -k / | awk 'NR > 1 {sub( "%", "", $4); print $4 }'

Quote:
but is there a more dynamic option than hardcoding $4 ...
thanks for all franklin vidyadhar johnson...

Use a variable for the column:
Code:
n=4
df -k / | awk -v col=$n 'NR > 1 {sub( "%", "", $col); print $col }'

[QUOTE]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to search a text in file and retrieve required lines following it with UNIX command?

I have requirement to search for a text in the file and retrieve required lines that is user defined with unix command. Eg: Find the text UNIX in the below file and need to return Test 8 & Test 9 Test 1 Test 2 Test 3 Test 4 UNIX Test 5 Test 6 Test 7 Test 8 Test 9 Result can... (8 Replies)
Discussion started by: Arunkumarsak4
8 Replies

2. Homework & Coursework Questions

awk command to retrieve record 23 and 89 from UNIX file

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I am looking for awk command to retrieve only the record number 23 and record number 89 from a unix file?... (6 Replies)
Discussion started by: rakeshp
6 Replies

3. UNIX for Beginners Questions & Answers

awk command to retrieve record 23 and 89 from UNIX file

Hi Everyone, I am looking for awk command to retrieve only the record number 23 and record number 89 from a unix file? Please let me know what is the awk command for this? Regards Rakesh (1 Reply)
Discussion started by: rakeshp
1 Replies

4. UNIX for Dummies Questions & Answers

Clipboard retrieve/paste command

I mainly use Max/MSP for my audio programming, but today I am working on a project that requires the use of shell. Is it possible to do this? Retrieve the contents of the clipboard. Send a keystroke to an application without loosing focus, for example, I want to initiate a paste command (with... (0 Replies)
Discussion started by: fhill2
0 Replies

5. Shell Programming and Scripting

Retrieve logs generated in last 10 mins from a log file using 'grep' command

HI All, I have a log file where the logs will be in the format as given below: 2011-05-25 02:32:51 INFO PROCESS STARTING 2011-05-25 02:32:52 INFO PROCESS STARTED . . . I want to retrieve only the logs which are less than 5 mins older than current time using grep... (3 Replies)
Discussion started by: rvhg16
3 Replies

6. Shell Programming and Scripting

How to retrieve data using awk command

I have a txt file with below data (textfile1.txt) select col1, col2 from Schema_Name.Table_Name1 select * from Schema_Name.Table_Name2 select col1, col2, col3 from Schema_Name.Table_Name3 select col1 from Schema_Name.Table_Name4 My output should look like Table_Name1 Table_Name2... (5 Replies)
Discussion started by: prasad4004
5 Replies

7. Shell Programming and Scripting

How to retrieve command line args one by on.

Hi, I have to store all the command line arguments into an array. I have the following code. ********************** #! /bin/sh set -A arr_no_updates i=1 while do arr_no_updates=$($i) echo ${arr_no_updates} i=$(($i+1)) done**************** (1 Reply)
Discussion started by: little_wonder
1 Replies

8. Shell Programming and Scripting

grep command to retrieve one file

The Sed/Grep command is really confusing me. I know I'm missing something that should be really easy to fix. My program displays multiple names after I ask it to display only one, How do I get it to do only one?? it looks like this: Please enter a name to display? >> John (A list then... (9 Replies)
Discussion started by: toejam
9 Replies

9. Solaris

command to retrieve user information

Hi, I want the command to retrieve the existing user information such as * authorization * Profile * role * exipre(expiration date of login) * inactive please tell me how to do that Thank you. (3 Replies)
Discussion started by: S_venkatesh
3 Replies

10. UNIX for Dummies Questions & Answers

How to retrieve the typed command

For examples, I have typed 4 commands in the command prompt: ls -la rm -rf /home/user1 du -k /home find . -name "abc.out" -print And now I want to retrieve the command which begin with letter "r" (i.e. rm -rf /home/user1), what can I do? (5 Replies)
Discussion started by: laum
5 Replies
Login or Register to Ask a Question