Visit Our UNIX and Linux User Community


Need to check the value greater than or less than and give out put to a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need to check the value greater than or less than and give out put to a file
# 1  
Old 01-11-2013
Need to check the value greater than or less than and give out put to a file

HI,

I have one file which is as below

Code:
cat /var/tmp/test1 | awk '{ print $3}'|grep -v affected
Data
----------
200.4

. The above 200 value is changable by the database script.
Now I need a script that checks the value 200.4 and the script shoud give out put if value is more than 225

Last edited by Scott; 01-11-2013 at 02:55 AM.. Reason: Code tags
# 2  
Old 01-11-2013
Code:
... awk '  $3 > 225.0 { print $3 } ' ...

Awk rule block idea:
Code:
rule1 { do some
        }

rule 2 { do some 
         }

Awk process every block for every input lines.

You can interrupt block process in "this line" using command next in the block => skip to the next line.

Rule can be regexp rule, normal comparing, ...

Code:
BEGIN { # special block - has done before 1st line has readed
            FS=";"
            OFS="-"
         }

/^#/  ||  NF < 10 { # 1st char is  # - comment or not enough fields
           next
         }

/ABC/ ~ $1  { # field 1 include string ABC
                 }

$3 + $5 > 100 { print "so big value" 
                    }

$1 == $2  {  print "equal"
              }

END { # special rule, done after input has readed
       }


Last edited by kshji; 01-11-2013 at 02:52 AM..
# 3  
Old 01-11-2013
Nice short intro to awk! Minor comment: regex matching is done reversely : $1 ~ /ABC/.
Code:
awk '/affected/ {next}
     $3 > 225.0 {print $3}
    '  /var/tmp/test1

should do the job for you.

Previous Thread | Next Thread
Test Your Knowledge in Computers #102
Difficulty: Easy
Unix, Linux and other Unix-like operating systems are a family of computer operating systems that are derived from DOS.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Move a TXT file greater or equal 355 MB with its corresponding .LST file

Good morning, i need your help please I need to move a .TXT file greater or igual 355 MB and its correspondent .LST file in a non recursive way The operating system is: uname -a SunOS server01c 5.10 Generic_144488-01 sun4u sparc SUNW,SPARC-Enterprise For example: rw-r--r-- 1 xptol ... (8 Replies)
Discussion started by: alexcol
8 Replies

2. Shell Programming and Scripting

search file for value greater than 'n' on each line and email

Hi, I need to write a script that will read each line of a CSV file, look for values greater than x seconds and email an alert. For the first part, I have one CSV per day, each line in the CSV has comma separated values. There are a total of 8 fields per line separated by commas. 6th and 7th... (3 Replies)
Discussion started by: ssid
3 Replies

3. Shell Programming and Scripting

SFTP bash put/get/rm check

Hello, i'm doing something like that #!/bin/sh sftp 172.18.255.140 <<End-Of-Session >> /usr/batch/logsftp.txt user batch ascii lcd /usr/batch get olaola.txt bye End-Of-Session   if then echo MAL >> /usr/batch/logsftp.txt echo $? >> /usr/batch/logsftp.txt exit $? else echo... (16 Replies)
Discussion started by: dexposit
16 Replies

4. UNIX for Dummies Questions & Answers

check if a decimal number is greater than zero

Hello, In my code I am checking to see if a variable that contains a decimal number is greater than 0 in the following manner: if do something fi However I am getting the error message (if $i for the current iteration holds 9.6352) command 9.6352 is not found How can I rectify... (5 Replies)
Discussion started by: Gussifinknottle
5 Replies

5. Shell Programming and Scripting

How to grep a pattern having value greater than 123 in a file?

Hi, I have a dynamically growing ascii file which has large data (both text and digits). I need to grep those lines having value greater than '123'. These numeric values may appear at anywhere in the line, hence I could not use awk to split to columns. So, please help me with the grep regular... (12 Replies)
Discussion started by: royalibrahim
12 Replies

6. Shell Programming and Scripting

Check numeric fields greater than zero, and delete lines if appropriate

This be the latest in my problems sorting through router logs... I'm half way there on a problem, but I've hit the limitation of my knowledge Got some router interface log files of type router01:GigabitEthernet9/24 is up, line protocol is up (connected) router01: 0 input errors, 0 CRC, 0... (7 Replies)
Discussion started by: Yorkie99
7 Replies

7. Shell Programming and Scripting

shell script to check file size greater than 50M

Hi All, OS:AIX 64 bits using korn shell. Requirement: shell script to check file size greater than 50M and send mail alert. Thanks for your time! Regards, (3 Replies)
Discussion started by: a1_win
3 Replies

8. Shell Programming and Scripting

check for the value of one particular field and give output in a different file

hi i need to check for the value of one particular field : in the output file. the file may contain many such records as below how to ???? *** Throttled with base name + key params! : : -518594328 : les.alarm.LBS12005 : les.alarm.LBS12005 : les : lessrv1 : les : 2328 : 0... (7 Replies)
Discussion started by: aemunathan
7 Replies

9. Shell Programming and Scripting

Find lines greater than 80 characters in a file

Hi, Can anyone please give me the grep command to find all the lines in a file that exceed 80 columns Thanks, gubbala (8 Replies)
Discussion started by: mrgubbala
8 Replies

10. Shell Programming and Scripting

File size greater than 0

ok I want to know how to touch a file and find out that it is greater than 0 then if it is not I want to fail the job other wise I want to success amnd go on. Can anyone help. Thanks Shannon Kammer (1 Reply)
Discussion started by: skammer1234
1 Replies

Featured Tech Videos