Any awk one liner to print df output?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Any awk one liner to print df output?
# 1  
Old 05-02-2013
Any awk one liner to print df output?

Hi,

OS = Solaris

Can anyone advise if there is a one liner to print specific output from a df -k output?

Running df from a command line, it sometimes gives me 2 lines for some volume. By re-directing the output to a file, it always gives 1 line for each.

Below is an example output, I've modified some of the volume names for confidential reason.

Code:
Filesystem            kbytes    used   avail capacity  Mounted on
server01:/vol/vol_01/01 319815680 246331968 73483712    78%    /nas_mnt/server01/vol_01/01
server01:/vol/vol_02/02 284164096 255495160 28668936    90%    /nas_mnt/server01/vol_02/02
server01:/vol/vol_03/03 8388608 7686776  701832    92%    /nas_mnt/server01/vol_03/03
server01:/vol/vol_04/04 12066816 6133128 5933688    51%    /nas_mnt/server01/vol_04/04
server01:/vol/vol_05/05 752877568 394102812 358774756    53%    /nas_mnt/server01/vol_05/05
server01:/vol/vol_06/06 3145728 2591832  553896    83%    /nas_mnt/server01/vol_06/06
server01:/vol/vol_07/07 6266880 5037936 1228944    81%    /nas_mnt/server01/vol_07/07

Can anyone advise if there is any way to print the lines matching where the capacity is >= 80%?

How do I change the one-liner below to print the whole line?

Code:
 
awk '{ print $5 }' /tmp/df.out | awk -F% '$1 >= 80 { print $1 }'

Ideally, I would want to convert the kbytes, used and avail to GB as well but the first one will give errors as it is the df header.

FYI, I am using df -k because some of my Solaris servers do not have the df -h so I need a df -k output but I want to convert them to GB via awk.

Any advice much appreciated. Thanks in advance.
# 2  
Old 05-02-2013
Code:
nawk '{S=$(NF-1);sub("%",X,S)}S>=80' /tmp/df.out

This User Gave Thanks to Yoda For This Post:
# 3  
Old 05-02-2013
Quote:
is any way to print the lines matching where the capacity is >= 80%?
Code:
$ grep "\([89][0-9]\)%\|100%" input
server01:/vol/vol_02/02 284164096 255495160 28668936    90%    /nas_mnt/server01/vol_02/02
server01:/vol/vol_03/03 8388608 7686776  701832    92%    /nas_mnt/server01/vol_03/03
server01:/vol/vol_06/06 3145728 2591832  553896    83%    /nas_mnt/server01/vol_06/06
server01:/vol/vol_07/07 6266880 5037936 1228944    81%    /nas_mnt/server01/vol_07/07

# 4  
Old 05-02-2013
Hi Yoda,

That works alright, anyway I can use awk instead?

If not, any way I can have the kbytes, used, avail to GB, i.e. have $2, $3, $4 divided by 1024/1024?

---------- Post updated at 07:08 PM ---------- Previous update was at 07:06 PM ----------

Quote:
Originally Posted by hanson44
Code:
$ grep "\([89][0-9]\)%\|100%" input
server01:/vol/vol_02/02 284164096 255495160 28668936    90%    /nas_mnt/server01/vol_02/02
server01:/vol/vol_03/03 8388608 7686776  701832    92%    /nas_mnt/server01/vol_03/03
server01:/vol/vol_06/06 3145728 2591832  553896    83%    /nas_mnt/server01/vol_06/06
server01:/vol/vol_07/07 6266880 5037936 1228944    81%    /nas_mnt/server01/vol_07/07

Hi,

Tried that but didn't work.
# 5  
Old 05-02-2013
Quote:
Originally Posted by hanson44
[CODE]$ grep "\([89][0-9]\)%\|100%" input
\| is a GNU extension. There is no alternation operator in standard basic regular expression grammar. Outside of GNU (and Busybox, probably, since they explicitly model their implementation on GNU tools), I don't believe that will work anywhere.

Portable equivalents:
Code:
grep -e '[89][0-9]%' -e 100% file

... and ...
Code:
grep '[89][0-9]%
100%' file

Regards,
Alister

Last edited by alister; 05-02-2013 at 10:07 PM..
This User Gave Thanks to alister For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk print output problem

Hello friends, I have written a script and i need to add some part into it so that i could print out more results depending on more conditions, This is the core part of the script which does the actual work: echo "$j" && nawk -v stat=$2 'NR==FNR &&... (1 Reply)
Discussion started by: EAGL€
1 Replies

2. Shell Programming and Scripting

Looking to improve the output of this awk one-liner

I have the following awk one-liner I came up with last night to gather some data. and it works pretty well (apologies, I'm quite new with awk, and don't know how to format this pretty-printed). You can see the output with it. awk '{if ($8 == 41015 && $21 == "requests") arr+=$20;if ($8 == 41015... (3 Replies)
Discussion started by: DeCoTwc
3 Replies

3. Shell Programming and Scripting

awk one liner to print to end of line

Given: 1,2,whatever,a,940,sot how can i print from one particular field to the end of line? awk -F"," '{print $2 - endofline}' the delimiter just happens to be a comma "," in this case. in other cases, it could be hypens: 1---2---whatever---a---940---sot (4 Replies)
Discussion started by: SkySmart
4 Replies

4. Shell Programming and Scripting

Awk script to run a sql and print the output to an output file

Hi All, I have around 900 Select Sql's which I would like to run in an awk script and print the output of those sql's in an txt file. Can you anyone pls let me know how do I do it and execute the awk script? Thanks. (4 Replies)
Discussion started by: adept
4 Replies

5. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

6. Shell Programming and Scripting

awk: Multiple search patterns & print in an one liner

I would like to print result of multiple search pattern invoked from an one liner. The code looks like this but won't work gawk -F '{{if ($0 ~ /pattern1/) pat1=$1 && if ($0 ~ /pattern2/) pat2=$2} ; print pat1, pat2}' Can anybody help getting the right code? (10 Replies)
Discussion started by: sdf
10 Replies

7. UNIX for Dummies Questions & Answers

awk {print $NF} output??

Hi, I am trying to debug an old script and have found the problem lies within this function: isIdoc() { # validate the file type fileType=`file $1 | awk '{print $NF}'` && echo 0 || echo 1 } My question is, how can I determine what is in the variable $fileType ? The program is... (1 Reply)
Discussion started by: vervette
1 Replies

8. Shell Programming and Scripting

using perl or awk to print output

suppose u have file File A A -> G C->D A -> R P->A File B A=1 C=2 D=3 E=4 F=5 G=6 H=7 I=8 K=9 L=10 M=11 (5 Replies)
Discussion started by: cdfd123
5 Replies

9. Shell Programming and Scripting

using awk to search and print output

suppose i have one file file A 18 24 30 35 38 45 55 Another file file B 08_46 A 16 V -0.36 0.23 E : 1.41 08_46 A 17 D -1.04 0.22 E : 0.84 08_46 A 18 Q -0.49 0.12 E : 0.06 08_46 A 19 G 0.50 0.14 E : 0.05 08_46 A 20 V ... (5 Replies)
Discussion started by: cdfd123
5 Replies

10. Shell Programming and Scripting

Execute the output of one liner print

Hello I wrote simple one liner that take RunTime *.exe and link them to the output of the compilation output: find ~/DevEnv/. -name "*.exe" | xargs ls -l | awk '{ x=split($9,a,"/"); print "ln -s " $9 " "a}' and it gives me the desire output , but how can I execute this ln command on every... (1 Reply)
Discussion started by: umen
1 Replies
Login or Register to Ask a Question

Featured Tech Videos