Sponsored Content
Top Forums Shell Programming and Scripting compute total from a text file Post 94747 by Perderabo on Tuesday 3rd of January 2006 03:58:45 PM
Old 01-03-2006
Your script has a lot of problems. Try this:
Code:
#/usr/bin/ksh
TheSum=0
while read Code Addend ; do
        [[ $Code = MAN* ]] && ((TheSum=TheSum+Addend))
done < test.20051219101007.fin
echo $TheSum
exit 0
$ ./scr2
297959288
$

The particular problem that attracted your attention is caused by the statement that starts out "Addend=$(". As you crawl from the end of the file towards the beginning, you are trying to store more and more data in the variable Addend. Eventually you overflow it and get unpredictable results.
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

grep running total/ final total across multiple files

Ok, another fun hiccup in my UNIX learning curve. I am trying to count the number of occurrences of an IP address across multiple files named example.hits. I can extract the number of occurrences from the files individually but when you use grep -c with multiple files you get the output similar to... (5 Replies)
Discussion started by: MrAd
5 Replies

2. Shell Programming and Scripting

to compute diskspace

Guys, have any idea for the script like this? also to compute w/ decimal. thanks a=10 b=20 c=30 d=40 if a < b then ( a -b)*1024 = free space b + (c -d) = total space if a > b then (b / d)*1024 = cpu (3 Replies)
Discussion started by: kenshinhimura
3 Replies

3. Shell Programming and Scripting

Calculate total space, total used space and total free space in filesystem names matching keyword

Good afternoon! Im new at scripting and Im trying to write a script to calculate total space, total used space and total free space in filesystem names matching a keyword (in this one we will use keyword virginia). Please dont be mean or harsh, like I said Im new and trying my best. Scripting... (4 Replies)
Discussion started by: bigben1220
4 Replies

4. Shell Programming and Scripting

Extract info from log file and compute using time date stamp

Looking for a shell script or a simple perl script . I am new to scripting and not very good at it . I have 2 directories . One of them holds a text file with list of files in it and the second one is a daily log which shows the file completion time. I need to co-relate both and make a report. ... (0 Replies)
Discussion started by: breez_drew
0 Replies

5. Shell Programming and Scripting

Output no. of rows and total value of a file to a new file

I am relatively new to Unix and I would be grateful if someone could help me with the syntax of a script. I am trying to write a Unix script against the file ‘ajtest.dat’ (see below) so that it outputs the number of rows and total value of column 3 in a file called ‘aj1’ as follows: No. of... (11 Replies)
Discussion started by: ajmutley
11 Replies

6. Shell Programming and Scripting

Total of a column from a file

Hi i need to calculate the total of a column from a file in ksh vi file.txt System : CBSE ent=0.1 me=Cap Subject Maths Science xxxxx 56 98 yyyy 89 67 ooo 67 32 Here i need to calculate only the total of Maths column alone i.e., 56+89+67 ... (4 Replies)
Discussion started by: Priresh
4 Replies

7. Shell Programming and Scripting

Compute in milisecond by use of mktime

Hi, I want to calculate diff b/w these starttime and endtime with use of mktime. I need response time in milisecond. I am using mktime to get these times. last three digits are in milisecond Starttime 2013-04-03 08:54:19,989 End time 2013-04-03 08:54:39,389 (9 Replies)
Discussion started by: random_thoughts
9 Replies

8. Shell Programming and Scripting

Compute average ignoring outliers of different segments within a dat file using awk

I have data files that look like this, say data.txt 0.00833 6.34 0.00833 6.95 0.00833 7.08 0.00833 8.07 0.00833 8.12 0.00833 8.26 0.00833 8.70 0.00833 9.36 0.01667 20.53 0.01667 6.35 0.01667 6.94 0.01667 7.07 0.01667 8.06 0.01667 8.10 0.01667 8.25 0.01667 8.71 0.01667 9.31... (7 Replies)
Discussion started by: malandisa
7 Replies

9. Shell Programming and Scripting

Match text to lines in a file, iterate backwards until text or text substring matches, print to file

hi all, trying this using shell/bash with sed/awk/grep I have two files, one containing one column, the other containing multiple columns (comma delimited). file1.txt abc12345 def12345 ghi54321 ... file2.txt abc1,text1,texta abc,text2,textb def123,text3,textc gh,text4,textd... (6 Replies)
Discussion started by: shogun1970
6 Replies
MONGOCURSOREXCEPTION(3) 						 1						   MONGOCURSOREXCEPTION(3)

The MongoCursorException class

INTRODUCTION
Caused by accessing a cursor incorrectly or a error receiving a reply. Note that this can be thrown by any database request that receives a reply, not just queries. Writes, commands, and any other operation that sends information to the database and waits for a response can throw a MongoCursorException. The only exception is new MongoClient() (creating a new connection), which will only throw MongoConnectionEx- ceptions. This returns a specific error message to help diagnose the problem and a numeric error code associated with the cause of the exception. For example, suppose you tried to insert two documents with the same _id: <?php try { $collection->insert(array("_id" => 1), array("w" => 1)); $collection->insert(array("_id" => 1), array("w" => 1)); } catch (MongoCursorException $e) { echo "error message: ".$e->getMessage()." "; echo "error code: ".$e->getCode()." "; } ?> error message: E11000 duplicate key error index: foo.bar.$_id_ dup key: { : 1 } error code: 11000 The following is a list of common errors, codes, and causes. Exact errors are in italics, errors where the message can vary are described in obliques. o cannot modify cursor after beginning iteration Code: 0 You are calling a method that sets up the query after executing the query. Reset the cursor and try again. An example: <?php try { $cursor = $collection->find(); var_dump($cursor->getNext()); // getNext() queried the database, it's too late to set a limit $cursor->limit(1); } catch (MongoCursorException $e) { echo "error message: ".$e->getMessage()." "; echo "error code: ".$e->getCode()." "; } // this will work, though: $cursor->getNext(); $cursor->reset(); $cursor->limit(1); ?> o Get next batch send errors Code: 1 Could not send the query to the database. Make sure the database is still up and the network is okay. o cursor not found Code: 2 The driver was trying to fetch more results from the database, but the database did not have a record of the query. This usually means that the cursor timed out on the server side: after a few minutes of inactivity, the database will kill a cursor (see MongoCursor.immortal(3) for information on preventing this). An example: <?php try { $cursor = $collection->find(); $cursor->getNext(); // sleep for 15 minutes sleep(60*15); while ($cursor->hasNext()) { $cursor->getNext(); } } catch (MongoCursorException $e) { echo "error message: ".$e->getMessage()." "; echo "error code: ".$e->getCode()." "; } ?> o cursor->buf.pos is null Code: 3 This may indicate you are out of RAM or some other extraordinary circumstance. o couldn't get response header Code: 4 A common error if the database or network goes down. This means that the driver couldn't get a response from the connection. o no db response Code: 5 This may not even be an error, for example, the database command "shutdown" returns no response. However, if you were expecting a response, this means the database didn't give one. o bad response length: %d, did the db assert? Code: 6 This means that the database said that its response was less than 0. This error probably indicates a network error or database corruption. o incomplete header Code: 7 Highly unusual. Occurs if the database response started out correctly, but broke off in the middle. Probably indicates a network problem. o incomplete response Code: 8 Highly unusual. Occurs if the database response started out correctly, but broke off in the middle. Probably indicates a network problem. o couldn't find a response Code: 9 If the response was cached and now cannot be located. o error getting socket Code: 10 The socket was closed or encountered an error. The driver should automatically reconnect (if possi- ble) on the next operation. o couldn't find reply, please try again Code: 11 The driver saves any database responses it cannot immediately match with a request. This exception occurs if the driver has already passed your request's response and cannot find your response in its cache. o error getting database response: errstr WSA error getting database response: errstr "errstr" is an io error reported directly from the C socket subsystem. On Windows, the error message is prefixed with "WSA". o Timeout error Code: 13 If there was an error while waiting for a query to complete. o couldn't send query: <various> Code: 14 C socket error on send. o max number of retries exhausted, couldn't send query Code: 19 The driver will automatically retry "plain" queries (not commands) a couple of times if the first attempt failed for certain reasons. This is to cause fewer exceptions during replica set failover (although you will probably still have to deal with some) and gloss over transient network issues. This can also be caused by the driver not being able to reconnect at all to the database (if, for example, the database is unreachable). Version 1.2.2+. ERRORS PASSED THROUGH BY THE DATABASE
Database errors should always trigger MongoCursorExceptions on queries. Error messages and codes are sent directly from the database and you should be able to see matching errors in the database log. A few common database errors are listed below: o E11000 duplicate key error index: foo.bar.$X dup key: { /* ... */ } Code: 11000 Database error for duplicate keys. o not master Codes: 10107, 13435, and 10058 Not master errors, piped through by the database. ach of these will cause the driver to disconnect and attempt to find a new primary. The actual error you get on failover may not be a "not master" error, depending on when the change in primary occurs. CLASS SYNOPSIS
MongoCursorException MongoCursorExceptionextends MongoException PHP Documentation Group MONGOCURSOREXCEPTION(3)
All times are GMT -4. The time now is 07:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy