Compare values for a pattern match and execute script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare values for a pattern match and execute script
# 1  
Old 08-02-2012
Compare values for a pattern match and execute script

Here in the input file

Code:
23:59:13,devicename,21,server1,700
23:59:13,devicename,22,server2,200
23:59:13,devicename,23,server3,200
23:59:13,devicename,24,server4,200
23:59:13,devicename,25,server5,200
23:59:13,devicename,26,server6,200
23:59:13,devicename,27,server7,200
23:59:23,devicename,28,server8,200
23:59:23,devicename,29,server9,200
23:59:23,devicename,30,server10,200

Here the value of first line and last column is 700 - Value A
The Average of value all the other is 200 - Value B

Need a script to be executed such

If ValueA > Value B AND also higher than 350 , then run a script sh dump.sh
# 2  
Old 08-02-2012
What have you tried so far?
# 3  
Old 08-02-2012
Nothing. I can print these values using awk and print these values

But need to put in the formula above
# 4  
Old 08-02-2012
Quote:
Originally Posted by necro98
Nothing. I can print these values using awk and print these values

But need to put in the formula above
please show the code calculating the average and the 'A>B'.
# 5  
Old 08-03-2012
Quote:
Originally Posted by vgersh99
please show the code calculating the average and the 'A>B'.
Thats exactly what i have requested from you people here , Hence you should show the code for it
# 6  
Old 08-03-2012
Code:
awk -F, 'NR==1{
valA=$NF;next}
{sum+=$NF}
END{
valB=sum/(NR-1)
if(valA>valB && valA>350)
 exit 1
}' infile || dump.sh


Last edited by elixir_sinari; 08-03-2012 at 04:48 AM..
# 7  
Old 08-03-2012
Quote:
Originally Posted by necro98
Thats exactly what i have requested from you people here , Hence you should show the code for it
We don't mean source code, we want an algorithm. Your question could be interpreted several ways, and I'm not sure which one of these is correct.

So what he means is, take a tiny sample of that data and show exactly what you'd do to calculate the number by hand, so that we can see the algorithm you want to follow.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rearrange or replace only the second line after pattern match or pattern match

Im using the command below , but thats not the output that i want. it only prints the odd and even numbers. awk '{if(NR%2){print $0 > "1"}else{print $0 > "2"}}' Im hoping for something like this file1: Text hi this is just a test text1 text2 text3 text4 text5 text6 Text hi... (2 Replies)
Discussion started by: invinzin21
2 Replies

2. Shell Programming and Scripting

How to use awk shell script to compare and match two files?

Basically, I have two files dupestest.txt 152,153 192,193,194 215,216 290,291 2279,2280 2282,2283haftest.txt 152,ABBOTS ROAD 153,ABBOTS ROAD 154,ABBOTS ROAD 155,ABBOTS ROAD 156,ABBOTS ROAD 157,ABBOTS ROADI want to find the numbers in dupestest.txt in haftest.txt... (4 Replies)
Discussion started by: amyc92
4 Replies

3. Shell Programming and Scripting

Adding Column Values Using Pattern Match

Hi All, I have a file with data as below: A,FILE1_MYFILE_20130309_1038,80,25.60 B,FILE1_MYFILE_20130309_1038,24290,18543.38 C,FILE1_dsc_dlk_MYFILE_20130309_1038,3,10.10 A,FILE2_MYFILE_20130310_1039,85,110.10 B,FILE2_MYFILE_20130310_1039,10,12.10... (10 Replies)
Discussion started by: angshuman
10 Replies

4. Shell Programming and Scripting

Script to match a pattern and print only the pattern and after that

Hi, I am writing a shell script to parse some files, and gather data. The data in the files is displayed as below. .......xyz: abz: ...... .......xyz: abz: ..... I have tried using awk and cut, bu the position of these values keep changing, so I can use awk and split it into columns. ... (14 Replies)
Discussion started by: Serena
14 Replies

5. Shell Programming and Scripting

Script to compare pattern and print a different pattern in each line

Hi, I am writing a shell script to parse some files, and gather data. The data in the files is displayed as below. .......xyz: abz: ......qrt: .... .......xyz: abz: ......qrt: ... I have tried using awk and cut, but the position of these values keep changing, so I wasn't able to get... (2 Replies)
Discussion started by: Serena
2 Replies

6. Shell Programming and Scripting

Pattern Match Script

Hi, I have a requirement in which I have to search the File name for pattern and if the pattern matches then I will have generate a value. Example: If $File_name='*NF' Then "NBC" Else $File_Name='SC*' Then "CBS" Else "FB" fi What is the best way to do this? I want to pass the... (6 Replies)
Discussion started by: btt3165
6 Replies

7. Shell Programming and Scripting

script that can do a pattern match

Hi, str1="Hello World" CheckPattern="drW" Need a search function that will do a character search. and return me which charater($CheckPattern) is not matched in $str1. Thanks in advance Madhu (1 Reply)
Discussion started by: madhuti
1 Replies

8. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

9. Shell Programming and Scripting

how to convert a shell script to a php script for displaying next word after pattern match

I have a shell script which I made with the help of this forum #!/bin/sh RuleNum=$1 cat bw_rules | sed 's/^.*-x //' | awk -v var=$RuleNum '$1==var {for(i=1;i<=NF;i++) {if($i=="-bwout") print $(i+3),$(i+1)}}' Basically I have a pages after pages of bandwidth rules and the script gives... (0 Replies)
Discussion started by: sb245
0 Replies

10. UNIX for Dummies Questions & Answers

mawk script to compare 2 files and report where they match

I have two files and would like a report of where they match. Example of file1: 1 1 1 2 2 2 13 14 15 4 4 4 15 16 17 100 102 1004 56 57 890 Example of file2: 2 2 2 16 10 11 45 22 35 13 14 15 1001 1002 3456 100 102 1004 (1 Reply)
Discussion started by: kenneth.mcbride
1 Replies
Login or Register to Ask a Question