Execution Problems with if statements


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execution Problems with if statements
# 1  
Old 12-20-2011
Execution Problems with if statements

Hi all,

I habe a file called test.log, which contain following data :

0.0
Code:
0.1
0.1
0.1
0.1
0.2
0.3
0.3
0.4
0.4
0.6
8.7
8.8
17.2

I want to show the data which gater than 9.0 But my script not working.
Script :

Code:
#!/bin/bash
ps -eo pcpu |grep-v"%CPU"> test.log
v=9.0
exec<test.log
while read line
do
if expr $line \> $v >/dev/null ; then
echo$line
fi
done
 


Last edited by Franklin52; 12-20-2011 at 06:29 AM.. Reason: Please use code tags for code and data samples, thank you
# 2  
Old 12-20-2011
Simplest Smilie
Code:
$ nawk '$0>9' infile
17.2

# 3  
Old 12-20-2011
Code:
if expr $line \> $v >/dev/null ; then

You don't need expr to do a numeric comparison.
Code:
if [ $line -gt $v ]; then

or
Code:
if [[ $line > $ v ]]; then

EDIT: Except that won't work for floats. Never mind me... Smilie
# 4  
Old 12-20-2011
Quote:
Originally Posted by CarloM
Code:
if expr $line \> $v >/dev/null ; then

You don't need expr to do a numeric comparison.

Code:
if [ $line -gt $v ]; then

or

Code:
if [[ $line > $ v ]]; then



EDIT: Except that won't work for floats. Never mind me... Smilie

It's not working properly.
# 5  
Old 12-20-2011
Code:
while read x; do res=`echo "$x > 9.0" | bc`; [ $res -eq 1 ] && echo $x; done < test.log

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execution Problems with awk

Ubuntu, Bash 4.3.48 Hi, I have this input file: a1:b2:c30:g4:h12:j7 and I want this output file: a1=g4:b2=h12:c30=j7 I can do it this with this code: awk -F':' '{print $1"="$4":"$2"="$5":"$3"="$6"}' INPUT > OUTPUTIn this case I have 6 columns, I calculate manually the half number of... (6 Replies)
Discussion started by: echo manolis
6 Replies

2. UNIX for Beginners Questions & Answers

Execution problems

How to find a word in a directory which contains many files? i just want to count how many such words are present in all the files? This is the code which i tried for a single file echo "Enter the file name:" read file echo "Enter the word to search:" read word if then echo "The count... (4 Replies)
Discussion started by: Meeran Rizvi
4 Replies

3. Shell Programming and Scripting

Execution problems with sed

Hi,I confused how to use sed to deal with big file. example: the big file have some different urls just with filename. how can i use sed to fetch url except file name and replace to other urls with filename? thanks!!! (11 Replies)
Discussion started by: hshzh359
11 Replies

4. Solaris

Execution problems with Mailx

Unable to send mail using mailx command. I am using solaris 5.9 I am trying to send notification for the scheduled jobs in crob but the mailx is not working. Checked the settings in submit.cf and sendmail.cf but unable to find the solution. Error message root@sshldb # nslookup mailhost... (8 Replies)
Discussion started by: Srinathkiru
8 Replies

5. Shell Programming and Scripting

Execution Problems

this my source file ************* fixed *************** Begin equipmentId : d9 processor : fox number : bhhhhhh Variable # 1: Id : 100 Type : 9 nType : s gType : 5f mType : 4 LField : England DataField : london Length ... (6 Replies)
Discussion started by: teefa
6 Replies

6. UNIX for Dummies Questions & Answers

Conditional execution of statements

Hi , I have a script which has multiple awk and sed commands like below. First one :- find /root/src/ -name "*csv" -size 0 -exec rm {} \; Second one: - ls *SRE*.txt > SRT_TRAN.dat rm *asr*.txt Third one :- find /root/src/ -name '*.csv' | while read FILENAME ; do awk... (2 Replies)
Discussion started by: shruthidwh
2 Replies

7. Shell Programming and Scripting

Execution Problems!!

i have been working on this for a about 12 hours today say's end of file un expected any idea's using the bourne shell and its driving me nuts worked fine in bash but prof says make it work in bourne and good luck worth 13% any help would be awesome #!/bin/sh trap "rm mnt2/source/tmp/* 2>... (1 Reply)
Discussion started by: mrhiab
1 Replies

8. Programming

execution problems with cron

how to store a date into file? and how we can access date from the file? ---------- Post updated at 06:09 AM ---------- Previous update was at 06:08 AM ---------- how we can store date in file? (1 Reply)
Discussion started by: causalmodi777
1 Replies

9. Shell Programming and Scripting

having problems with IF statements

below is a sample of the shell script im trying to get working. if the script is run with no data it should display the usage. if data1 is given it should grep with todays date and if data1 and a date are giving it should grep using the date given. please let me know what im doing wrong ive tried... (5 Replies)
Discussion started by: jrelax
5 Replies

10. Shell Programming and Scripting

Major Awk problems (Searching, If statements, transposing etc.)

Please bare with me as task is very detailed and I'm extremely new to Awk/sed. Keep in mind I'm running windows so I'm using a dos prompt The attachment is a server report that I'm trying to manipulate with little success. For each server, I need to take the most recent information about them... (2 Replies)
Discussion started by: Blivo
2 Replies
Login or Register to Ask a Question