need a df -h oneliner..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need a df -h oneliner..
# 1  
Old 12-08-2011
need a df -h oneliner..

can any one suggest some one liner such that when executed will display df -h output of the mount points that are 90% or more that it.. and not the remaining..
# 2  
Old 12-08-2011
Code:
 
df -h | grep "9[0-9]%"

These 2 Users Gave Thanks to itkamaraj For This Post:
# 3  
Old 12-08-2011
wowwwww

wow.. Thanks.. i was thinking about logics , scripts.. silly me.. i forgot the sweet little tool called grep Smilie Thanks ..

---------- Post updated at 05:27 AM ---------- Previous update was at 04:50 AM ----------
i found one more way!!!


Code:
df -h | awk '$5>=70{print}'

df -h output
Code:
# df -h
Filesystem             size   used  avail capacity  Mounted on
/dev/dsk/c0d0s0        4.6G   3.6G  1020M    79%    /
/devices                 0K     0K     0K     0%    /devices
ctfs                     0K     0K     0K     0%    /system/contract
proc                     0K     0K     0K     0%    /proc
mnttab                   0K     0K     0K     0%    /etc/mnttab
swap                   576M   924K   575M     1%    /etc/svc/volatile
objfs                    0K     0K     0K     0%    /system/object
sharefs                  0K     0K     0K     0%    /etc/dfs/sharetab
/usr/lib/libc/libc_hwcap1.so.1
                       4.6G   3.6G  1020M    79%    /lib/libc.so.1
fd                       0K     0K     0K     0%    /dev/fd
swap                   575M    84K   575M     1%    /tmp
swap                   575M    40K   575M     1%    /var/run
/hgfs                   16G   4.0M    16G     1%    /hgfs
tank                   464M    18K   464M     1%    /tank
#

using grep command
Code:
# df -h | grep "7[0-9]%"
/dev/dsk/c0d0s0        4.6G   3.6G  1020M    79%    /
/usr/lib/libc/libc_hwcap1.so.1   4.6G   3.6G  1020M    79%    /lib/libc.so.1

using AWK command
Code:
# df -h | awk '$5>=70{print}'
Filesystem             size   used  avail capacity  Mounted on
/dev/dsk/c0d0s0        4.6G   3.6G  1020M    79%    /
/usr/lib/libc/libc_hwcap1.so.1   4.6G   3.6G  1020M    79%    /lib/libc.so.1

well , when using awk the header field is not omitted
Code:
Filesystem             size   used  avail capacity  Mounted on

# 4  
Old 12-08-2011
Code:
nawk 'NR>1 && $5>=70' inputfile.txt

# 5  
Old 12-08-2011
cool.. there is always another way :)

can you please explain about the nawk command you pasted.. i am not familiar with nawk
# 6  
Old 12-08-2011
NAWK stands for “New AWK”. This is AT&T’s version of the Awk

we have one more awk. ie..
GAWK stands for “GNU AWK”. All Linux distributions comes with GAWK. This is fully compatible with AWK and NAWK.

instead of nawk, you can try with awk also.

AWK Vs NAWK Vs GAWK (link removed)
# 7  
Old 12-09-2011
a tweak needed :(

the ouput of this one liner has gone little out of format..
Code:
# df -h | awk '$5>=70{print}'
Filesystem             size   used  avail capacity  Mounted on
/dev/dsk/c0d0s0        4.6G   3.6G  1020M    79%    /
/usr/lib/libc/libc_hwcap1.so.1   4.6G   3.6G  1020M    79%    /lib/libc.so.1

see the below normal output of df -h which has the even spacing..

Code:
# df -h / /lib/libc.so.1
Filesystem             size   used  avail capacity  Mounted on
/dev/dsk/c0d0s0        4.6G   3.6G  1020M    79%    /
/dev/dsk/c0d0s0        4.6G   3.6G  1020M    79%    /
#

is there anyway i can get the output in the same format ?

i figured out one way.. but i feel there would a better and cleaner way
Code:
# df -h | awk '$5>=70{print}' | awk '{print $6}' | xargs df -h 2>/dev/null

please help me out..

---------- Post updated 12-09-11 at 04:13 AM ---------- Previous update was 12-08-11 at 10:18 AM ----------

Code:
df -h | awk '{if($5>=70&&NR!=1){print $6}}' | xargs df -h

The previous code printed the heading 'Mounted' followed by the mount point names.. that is the reason it was throwing error. Now the above pasted code works fine Smilie

But would be eager to know if there is another way for this
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - oneliner vs multiple line .

Dear Awk Experts, I can write oneliner some time but find difficulty writing like a flow of a program in multiple lines, could you please help how to write awk program , like long awk programs, any help to start with, For example, How to write this in multiple line: ls -l | awk... (6 Replies)
Discussion started by: rveri
6 Replies

2. Shell Programming and Scripting

Oneliner ---split string to character by piping shell output to perl

Hello, I was trying to split a string to characters by perl oneliner. echo "The quick brown fox jumps over the lazy dog" | perl -e 'split // ' But did not work as with bash script pipe: echo "The quick brown fox jumps over the lazy dog" | fold -w1 | sort | uniq -ic 8 1 T 1... (6 Replies)
Discussion started by: yifangt
6 Replies

3. Shell Programming and Scripting

nawk oneliner to find and replace a pattern

Hi, I need to replace the ip 1.1.1.1 with the name test.sol.box . I have tried and come up with following code. do we have any other way of doing this with nawk?? Data: #This is a test setup.Please enter your values and corresponding port number here ########################## Server Host... (5 Replies)
Discussion started by: chidori
5 Replies

4. UNIX for Dummies Questions & Answers

oneliner for adding header and trailer

for example, i have a file with below content: 123413 866688 816866 818818 i want the output as: This is header 123413 866688 816866 818818 This is trailer i am able to achieve it using a bash script. (2 Replies)
Discussion started by: pandeesh
2 Replies

5. Shell Programming and Scripting

perl oneliner to cut the file

Hi I have a file say text.txt and has data as below. text.txt ------- /abc/def/tom/hanks /abc/def/al/pacino /def/dgg/matt/damon Now I have to cut the field 3 and field 4 treating / as delimiter and save in the same file. Below is the how the output should be in the same file. I... (1 Reply)
Discussion started by: lijjumathew
1 Replies

6. Shell Programming and Scripting

perl oneliner not works .pl script

I am trying to take first 3 columns in a file which matches the word "abc", but i am getting the below error, <error> Global symbol "@F" requires explicit package name at ./new.pl </error> whereas when i give the below,grep abc /home/test/file.txt|perl -lane 'print \"$F $F $F\" in unix prompt... (4 Replies)
Discussion started by: anspks
4 Replies

7. Shell Programming and Scripting

oneliner:sing SED on a specific column

is this possible a one liner sed command. I have a text file ex. from : xxx yyy ZZZ /test/devl/aasdasd.log1 xxx yyy ZZZ /test/devl/aasdasd.log2 to : xxx yyy ZZZ /test/prod/aasdasd.log1 xxx yyy ZZZ /test/prod/aasdasd.log2 and I want to sed only the fourth column sed 's/devl/prod/g' ... (8 Replies)
Discussion started by: chaseeem
8 Replies
Login or Register to Ask a Question