Aggregate values in a file & compare with sql output


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Aggregate values in a file & compare with sql output
# 1  
Old 09-02-2007
Aggregate values in a file & compare with sql output

Hi,

I have a file containing the following data:

junk123junk723itemcode001qty01price10total10junkjunk
junk123junk723itemcode002qty02price10total20junkjunk
..
..
..
could be 5000+ lines

I have an algo and need a code to implement this:
1. Linecount = wc -l (should give 5000)
2. For i = 1 to linecount (loops 5000 times)
3. pick up the value from total and aggregate them ie 10 + 20 = 30
4. This should be done fr all the lines and the total aggregated total in a variable called TOTAL.
5. The total aggregate should be compared against a database query ie:

total_database=`sqlplus -s un/pw@TNS_NAME<<END
set pagesize 0
set feedback off
set heading off
set echo off
set verify off
select total from results;
exit;
END`
echo "$total_database"

If $ total_database = $TOTAL then pass, else echo fail..

Can someone kindly help me out with this.I hope I gave in enough info..

Thanks and Regards,
Ron.
shiroh_1982
# 2  
Old 09-02-2007
assuming the total is always 2 digits.
Code:
# total=$(awk '{match($0,"total");c=c+substr($0,RSTART+5,2)}END{print c}' file)
# echo $total
30

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to compare to values returned from sql in shell scripting?

hey i am using this code to connect to sql , store the value in variable and then compare it with another variable after some time by executing the same query but the desired result is not coming #!/bin/bash val=$(sqlplus -s rte/rted2@rel76d2 <<ENDOFSQL set heading off set feedback off... (11 Replies)
Discussion started by: ramsavi
11 Replies

2. Shell Programming and Scripting

LINUX - How to compare the values in 2 files & exit from the script

Hi All, I have a requirement where I need to compare 2 files & if the values in the files match, it should proceed, else exit the script without proceeding further. For e.g : Scenario 1 In this case, the script should exit without proceeding further. Scenario 2 In this case, the script... (7 Replies)
Discussion started by: dsfreddie
7 Replies

3. Shell Programming and Scripting

Compare values in two files. For matching rows print corresponding values from File 1 in File2.

- I have two files (File 1 and File 2) and the contents of the files are mentioned below. - I am trying to compare the values of Column1 of File1 with Column1 of File2. If a match is found, print the corresponding value from Column2 of File1 in Column5 of File2. - I tried to modify and use... (10 Replies)
Discussion started by: Santoshbn
10 Replies

4. Shell Programming and Scripting

compare columns for equal values and output a summary

Hi all I am trying to scan a file that has 3 columns: red blue 123351 red blue 848655 red blue 126354 red blue 023158 black white 654896 red blue 650884 I want an output that sums the rows that have matching columns 1 and 2 :wall: red blue has 5 entries black white has 1 entry ... (4 Replies)
Discussion started by: reno
4 Replies

5. Shell Programming and Scripting

How to Pass the Output Values from the PL/SQL Procedure to Shell Script?

hi, Could anyone tell me how to pass the output values of the PL/SQL procedure to Shell script and how to store that values in a shell script variable... Thanks in advance... (5 Replies)
Discussion started by: funonnet
5 Replies

6. Shell Programming and Scripting

Output of Unix & SQL in same file

output of Unix & sql in same file hi all, am working on shell script, i need to format data in such a way that both my Unix commands output & my sql output should be in a same file. I am able to redirect both output in separate files. for sql output: sqlplus -s... (6 Replies)
Discussion started by: bankimmehta
6 Replies

7. Shell Programming and Scripting

Awk Multiple Files & Aggregate

file 1: 70|236|PPS|0501011818|mms|20090706|001452|00000024|2|0000000000000000|00000|0000000000|0000000000|40948000|1 70|236|PPS|0501020076|mms|20090705|204408|00000019|2|0000000000000000|00000|0000000000|0000000000|40947930|1... (3 Replies)
Discussion started by: magedfawzy
3 Replies

8. Shell Programming and Scripting

Compare two file & output

Hi every body i have a problem need help urgently file 1 (approx 200K entries) aaaaa bbbb cccccc dddd ffff file 2 (approx 2 million entries) aaaaa,1,ee,44,5t,6y, bbbb,3,ff,66,5u,8r, cccccc, ..... dddd, ..... eeeeee, ..... ffff, ...... (5 Replies)
Discussion started by: The_Archer
5 Replies

9. Shell Programming and Scripting

Sum values & compare with footer

Hi All, I have a file abc.txt with 3 fileds. Field 3 contains amount. Also at the end of file there is a Footer record, which contains total amount. I need to calculate total sum of these fields & need to compare it with footer record. I have serched in thi site, many has asked this... (7 Replies)
Discussion started by: Amit.Sagpariya
7 Replies

10. Shell Programming and Scripting

small script - get sql output & write into txt

Hi, how can I write a small script to run the following statement and output the result into check_result.txt select /*+RULE*/ tapname from typetbl where tapname like 'AA%' and rejectcode=9; Normally, I just type sql and get into SQL> (2 Replies)
Discussion started by: happyv
2 Replies
Login or Register to Ask a Question