UNIX shell script - cut specified line and perform loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting UNIX shell script - cut specified line and perform loop
# 1  
Old 06-06-2013
UNIX shell script - cut specified line and perform loop

Guys,

I have a requirement as below.

consider,if i use df command, its getting the below output.

Code:
file system    kbytes   used   avail  %used Mounted on
/dev/sample/   45765   40000 5765  50%    /
/dev/filesys/   30000    20000 1000  80%    /u
....
....

Now i wanted to cut the /u %used value only, and if its greater than or equal to 80% (If its less than 80%, it should not perform any action) then i need to perform a function to be called.
can anyone please help me on this?

Appricieate your help!!!

Thanks
Aravind

Last edited by Scott; 06-06-2013 at 03:31 AM.. Reason: Please use code tags
# 2  
Old 06-06-2013
Hello,


Could you please use the following code and let me know if that helps you.
Code:
vi test.ksh
### saving Output to a file named test1 for df.
 
df | grep -v "%used Mounted on" > test1
 
#### Threshould value here.
THD=70
while read line
do
  a=`echo $line | awk '{print$1}' | cut -f1 -d %`
  b=`echo $line | awk '{print$2}'`
  if [[ $a -ge $THD ]]
  then
    echo $b "is having more than 70% value please check."
    echo "Call function here."
  fi
done < "test1"


to run script please use ksh test.ksh

R. Singh

Last edited by Scott; 06-06-2013 at 04:08 AM.. Reason: Code tags, please...
# 3  
Old 06-06-2013
Thanks for the reply Singh. I have tried but getting syntax error. I am trying to figure out.
# 4  
Old 06-06-2013
please paste the error here, lets see if I can help you in case you are not able to find out. Kindly get back to me for same.

R. Singh
# 5  
Old 06-06-2013
This is the error am getting

Code:
syntax error at line 11: ``' is not matched.

Thanks

Last edited by Scott; 06-06-2013 at 04:30 AM.. Reason: Code tags, please...
# 6  
Old 06-06-2013
reply

Please paste me the line 11 seems backtick ` didn't closed properly in the line.
So you can give me that line and I will try to figure out the issue then.


R. Singh
# 7  
Old 06-06-2013
Replace all back tics `code` with parentheses $(code)
Its much more easy to see start, stop.
Better with nesting.
Less problem with typo using ´ instead of `or '

Like this:
Code:
a=$(echo $line | awk '{print$1}' | cut -f1 -d %)

Or only awk
Code:
a=$(echo $line | awk '{split($1,a,"%");print a[1]}')

or
Code:
a=$(awk '{split($1,a,"%");print a[1]}' <<< $line )


Last edited by Jotne; 06-06-2013 at 04:44 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script UNIX to read text file line by line

i have a text file as belows, it includes 2 columns, 1st is the column name, 2nd is the file_name data_file.txt column_name file_name col1 file1 col2 file2 col3 file1 col4 file1 col5 file2 now, i would like to... (4 Replies)
Discussion started by: tester111
4 Replies

2. Shell Programming and Scripting

How to read a two files, line by line in UNIX script and how to assign shell variable to awk ..?

Input are file and file1 file contains store.bal product.bal category.bal admin.bal file1 contains flip.store.bal ::FFFF:BADC:CD28,::FFFF:558E:11C5,6,8,2,1,::FFFF:81C8:CA8B,::FFFF:BADC:CD28,1,0,0,0,::FFFF:81C8:11C5,2,1,0,0,::FFFF:81DC:3111,1,0,1,0 store.bal.... (2 Replies)
Discussion started by: veeruasu
2 Replies

3. Shell Programming and Scripting

UNIX shell script for loop issue

Guys, Please help on the below. sample.prm /u/test/: mail=123@gmail.com purgedays=30 zipdays=7 purgefile=log.gz zipfile=log /u/test/: mail=123@gmail.com purgedays=30 purgefile=txt.gz zipfile=txt zipdays=7 (1 Reply)
Discussion started by: AraR87
1 Replies

4. Shell Programming and Scripting

Shell script to perform appending of .sql files

Hi, We are having multiple .sql files generated programatically which is not containing.. create or replace -- at the start and / -- at the end We need to append those .sql files with the above 2 statements at their respective positions. We will be really thankful to get responses... (6 Replies)
Discussion started by: Rami Reddy
6 Replies

5. Shell Programming and Scripting

Unix Script -- Unable to perform division

I'm new to scripts, i wrote the below script to capture the percentage of FreeMemory available in Linux box. Output of UsedfreeMemory is displayed as '0'. I'm expecting the output like 0.89 (or) .89 --- ( 0.89 perferable) Anyone can help me on this pls. ... (3 Replies)
Discussion started by: murali1687
3 Replies

6. Shell Programming and Scripting

How to perform floating division in shell script?

I want to perform the below division operation in shell script and round the value. val1=6000 val2=5000 res=val1/val2 ----> 1.2---> Round to 2 Please help. (3 Replies)
Discussion started by: vel4ever
3 Replies

7. UNIX for Dummies Questions & Answers

How to perform string replace in shell script?

I have value like ABCDEF,BBCCDD in a shell variable, now i would like to have ABQWEF,BBQWDD in the same shell variable. How can i replace the char at position 3&4 with QW in shell script? (3 Replies)
Discussion started by: vel4ever
3 Replies

8. Shell Programming and Scripting

shell script - search a file and perform some action

hi, i have a service on unix platform, it will generate traces in a particular folder i want to check using shell script if traces exist, then perform some action else continue to be in loop. filename is service.tra can you please help? thanks (4 Replies)
Discussion started by: gauravah
4 Replies

9. Shell Programming and Scripting

cut first line in unix

Hi I need to cut the first line of a line and append it at last of the same file, when i run the script for the second time.. plz help on this.. thanks (1 Reply)
Discussion started by: raghulshekar
1 Replies

10. Shell Programming and Scripting

Unix Shell Script to loop over Directory and send Filesname as parameters

Hi there I'm new to UNIX scripting; I’m stuck with the following I have an Oracle SQL script that takes three parameters 1- File Name 2- File Path 3- File creation date Under UNIX I have a folder where files will be placed frequently and I need to upload those files to Oracle, what I need... (3 Replies)
Discussion started by: windjashi
3 Replies
Login or Register to Ask a Question