intent: df -kh | filter based on capacity (used space) column where % > 85


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting intent: df -kh | filter based on capacity (used space) column where % > 85
# 1  
Old 10-16-2008
intent: df -kh | filter based on capacity (used space) column where % > 85

I want to accomplish this in sh, however if the capability exists only in other shells elsewhere that's acceptable.

% df -kh
Filesystem size used avail capacity Mounted on
...
/dev/dsk/c0t0d0s1 103G 102G 23M 100% /export/DISK15
...
# output truncated for brevity

my objective is to create a script to filter and print all entries in a df -kh output:
- commands available to !/bin/sh - preferred
- where the % value in the capacity column is greater than 85%
- i want the resulting output to print the original entry from df -k output
to contain the filesystem capacity and mount-point

- also I'd like to sort by alphanumeric character contained in the Mounted on column, this is nice to have, not necessary** I didn't have much success with the sort -k 6,6d or 6,6d operands


I'm relatively new to the UNIX environment, windows guy by trade so get the boos and jeers out of your systems up front. Smilie

Back to business:

I was thinking foreach statements, not sure how to feed each line to the foreach statement where a carriage return/or new line character would be used as the field separator in foreach input; awk coupled with gt statements but not really sure if that's the best tool. I suspect maybe test statements gotta be used, but I'm drawing blanks as to how to accomplish this and put it together since I have very limited exposure to scripting. I have no idea how to designate carriage returns/new line characters as the field separator for foreach input, remember I'm new I've read documentation for all over so my direction could be severely misguided or even out of correct context.

here are my initial thoughts, this could clarify my intentions

df -kh
either pipe output to input for "foreach command statement" or redirect to temp file, << EOFs (here document) acceptable, probably preferred for conservation of space each time command is run to avoid generating file backlog

either temp file or << EOF provide foreach inputs to be taken for action, at which point I want the % value in the capacity column compared with gt statement against value of 85%.

Then any of the original entries whose capacity column value evaluates as true for the gt 85% comparison, I want those printed and ultimately sorted by alphanumeric value of the mountpoint.

Please let me know if you can help and/or if you want me to do any further footwork, be specific in any following requests so we can get it done right and with minimal delay. Thanks a bunch in advance.

your friendly neighborhood programmar!
# 2  
Old 10-16-2008
so I discovered some info on this site AFTER I posted, I guess this isn't uncommon using the suggested links for related posts.

anyway,

syntax I got for accomplishing everything I wanted ended up being

# df -kh | grep /export | awk '$5 >= 85' | sort 6,6d

HOWEVER this omits any entries where the capacity field has a value of 100%, last time I checked...that was more than 85. What am I missing?
# 3  
Old 10-16-2008
Useless use of grep
Code:
df -kh | awk '/\/export/ && int($5) >= 85'

# 4  
Old 10-16-2008
Quote:
Originally Posted by danmero
Useless use of grep
Code:
df -kh | awk '/\/export/ && int($5) >= 85'


error:
Unmatched '


thanks for your input though. If you don't mind explaining, could you go into detail of the structure of this statement and why you did that.

I'm still trying to figure out the placement/requirement/caveats of (), [],{}, of which you're only using parentheses here. Hopefully you understand what I'm asking.

Am I right to assume the single quotes are to group the commands together or are they dual purpose in order to execute commands within the awk command as well as grouping the contents. kind of like sub-shell execution?

I'm familiar with using the forward-slash to initiate a search as within vi, less environments, then you're using the back-slash to escape the following forward-slash metacharacter which is a part of the search string...what's the last forward-slash's purpose in that statement? Also, the open-close parentheses around the integer and column id? If you have reference material, I'll gladly take as response.
# 5  
Old 10-16-2008
Code:
df -kh |       \  # Pipe the output of df to awk
awk '             # Start the awk script
/\/mnt/        \  # Grep for pattern(first condition)
&&             \  # add a second condition (and)
int($5) >= 85  \  # Check if integer of $5 is greater that 85(second condition) 
'                 # End awk script

# 6  
Old 10-16-2008
Code:
df -kh | \
awk '{
   if (NF==1) {
      getline l
      gsub(" +"," ",l)
      $0=$0l
      l=""
   }
   if ($(NF-1)+0 > 85)
      print
}' | \
sort -k6,6

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Filter tab file based on column value

Hello I have a tab text file with many columns and have to filter rows ONLY if column 22 has the value of '0', '1', '2' or '3' (out of 0-5). If Column 22 has value '0','1', '2' or '3' (highlighted below), then remove anything less than 10 and greater 100 (based on column 5) AND remove anything... (1 Reply)
Discussion started by: nans
1 Replies

2. Shell Programming and Scripting

Filter Row Based On Max Column Value After Group BY

Hello Team, Need your expertise on following: Here is the set of data: C1|4|C1SP1|A1|C1BP1|T1 C1|4|C1SP2|A1|C1BP2|T2 C2|3|C2SP1|A2|C2BP1|T2 C3|3|C3SP1|A3|C3BP1|T2 C2|2|C2SP2|A2|C2BP2|T1 I need to filter above date base on following two steps: 1. Group them by column 1 and 4 2.... (12 Replies)
Discussion started by: angshuman
12 Replies

3. Shell Programming and Scripting

UNIX command -Filter rows in fixed width file based on column values

Hi All, I am trying to select the rows in a fixed width file based on values in the columns. I want to select only the rows if column position 3-4 has the value AB I am using cut command to get the column values. Is it possible to check if cut -c3-4 = AB is true then select only that... (2 Replies)
Discussion started by: ashok.k
2 Replies

4. Shell Programming and Scripting

Filter on one column and then perform conditional calculations on another column with a Linux script

Hi, I have a file (stats.txt) with columns like in the example below. Destination IP address, timestamp, TCP packet sequence number and packet length. destIP time seqNo packetLength 1.2.3.4 0.01 123 500 1.2.3.5 0.03 44 1500 1.3.2.5 0.08 44 1500 1.2.3.4 0.44... (12 Replies)
Discussion started by: Zooma
12 Replies

5. Linux

Filter a .CSV file based on the 5th column values

I have a .CSV file with the below format: "column 1","column 2","column 3","column 4","column 5","column 6","column 7","column 8","column 9","column 10 "12310","42324564756","a simple string with a , comma","string with or, without commas","string 1","USD","12","70%","08/01/2013",""... (2 Replies)
Discussion started by: dhruuv369
2 Replies

6. Shell Programming and Scripting

awk filter based on column value (variable value)

Hi, I have a requirement to display/write the 3rd column from a file based on the value in the column 3. Ex: Data in the File (comma delimited) ID,Value,Description 1,A,Active 1,I,Inactive 2,S,Started 1,N,None 2,C,Completed 2,F,Failed I need to first get a list of all Unique IDs in... (7 Replies)
Discussion started by: kiranredz
7 Replies

7. UNIX for Dummies Questions & Answers

Extracting rows from a space delimited text file based on the values of a column

I have a space delimited text file. I want to extract rows where the third column has 0 as a value and write those rows into a new space delimited text file. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

8. Shell Programming and Scripting

Filter the column and print the result based on condition

Hi all This is my output of the some SQL Query TABLESPACE_NAME FILE_NAME TOTALSPACE FREESPACE USEDSPACE Free ------------------------- ------------------------------------------------------- ---------- --------- ---------... (2 Replies)
Discussion started by: jhon
2 Replies

9. Shell Programming and Scripting

filter out all the records which are having space in the 8th filed of my file

I have a file which is having fileds separtaed by delimiter. Ex: C;4498;qwa;cghy;;;;40;;222122 C;4498;sample;city;;;;34 2;;222123 C;4498;qwe;xcbv;;;;34-2;;222124 C;4498;jj;sffz;;;;41;;222120 C;4498;eert;qwq;;;;34 A;;222125 C;4498;jj;szxzzd;;;;34;;222127 out of these records I... (3 Replies)
Discussion started by: indusri
3 Replies

10. Shell Programming and Scripting

filter based on column value

I have a file with colon separated values.. the sample is attached below. No of fields in each record/line is dependent on the value of field53. What I need to do is to design a special filter based on specific requirement of some match of values in particular column or combination of columns. ... (2 Replies)
Discussion started by: rraajjiibb
2 Replies
Login or Register to Ask a Question