expr Field 1 + Field 2 Since when does 2 positives make a negative


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting expr Field 1 + Field 2 Since when does 2 positives make a negative
# 1  
Old 04-01-2010
Probably exceeding your INT_MAX in limits.h

A typical limit is 2147483647.
Your value would normally be 2148302046 which is greater
and hence you get the negative, since bits were truncated
from the most significant side of your result.

'bc' will give you the result you want, but you would have to
continue to use 'bc' to do anything useful with that result
other than report it.

Code:
 
field1=2100002
field2=2146202044
 
echo "$field1 + $field2" | bc
2148302046
 
result=$(echo "$field1 + $field2" | bc)
echo $result
2148302046

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to adjust coordinates in field based on sequential numbers in another field

I am trying to output a tab-delimited result that uses the data from a tab-delimited file to combine and subtract specific lines. If $4 matches in each line then the first matching sequential $6 value is added to $2, unless the value is 1, then the original $2 is used (like in the case of line... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Display combination of 4 field uniqe record and along with concatenate 5th and 6th field.

Table ACN|NAME|CITY|CTY|NO1|NO2 115|AKKK|ASH|IND|10|15 115|AKKK|ASH|IND|20|20 115|AKKK|ASH|IND|30|35 115|AKKK|ASH|IND|30|35 112|ABC|FL|USA|15|15 112|ABC|FL|USA|25|20 112|ABC|FL|USA|25|45 i have written shell script using cut command and awk programming getting error correct it and add... (5 Replies)
Discussion started by: udhal
5 Replies

3. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

4. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

5. Shell Programming and Scripting

Make a new field with a word on it

i have a file contains as below: : 12 32 qw 21 44 qq ### 11 90 er 88 23 sa ### i want to add new field with constant string "madd" between 2nd field and 3rd field of each record, so the desired output will be: : 12 32 madda qw 21 44 madda qq ### 11 90 madda er 88 23 madda sa ### (10 Replies)
Discussion started by: oreka18
10 Replies

6. 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

7. Shell Programming and Scripting

awk, comma as field separator and text inside double quotes as a field.

Hi, all I need to get fields in a line that are separated by commas, some of the fields are enclosed with double quotes, and they are supposed to be treated as a single field even if there are commas inside the quotes. sample input: for this line, 5 fields are supposed to be extracted, they... (8 Replies)
Discussion started by: kevintse
8 Replies

8. Shell Programming and Scripting

How to select or make reference to, part of a field

For a field format such as AAL1001_MD82, how do I select(and use in if statement) only the last four elements( in this case MD82) or the first three elements (in this case AAL)? For instance, how do I do the following - if first three elements of $x == yyy, then ... (5 Replies)
Discussion started by: akshaykr2
5 Replies

9. Shell Programming and Scripting

Sort alpha on 1st field, numerical on 2nd field (sci notation)

I want to sort alphabetically on the first field and sort in descending numerical order on the 2nd field. With a normal "sort -r -n" it does this: abc ||| 5e-05 ||| bla abc ||| 3 ||| ble def ||| 1 ||| abc def ||| 0.2 ||| def As you can see it ignores the fact that 5e-05 is actually 0.00005... (1 Reply)
Discussion started by: FrancoisCN
1 Replies

10. Shell Programming and Scripting

using awk make an field as 5 digit and display

using awk convert 3 rd fileld of file as 5 digit and then display changed file. like 1 2 23445 3452 3343 3 5 6 6 ================ o/p:- 1 2 23445 3452 03343 3 5 00006 6 (1 Reply)
Discussion started by: RahulJoshi
1 Replies
Login or Register to Ask a Question
CUBRID_FIELD_TABLE(3)							 1						     CUBRID_FIELD_TABLE(3)

cubrid_field_table - Return the name of the table of the specified field

SYNOPSIS
string cubrid_field_table (resource $result, int $field_offset) DESCRIPTION
This function returns the name of the table of the specified field. This is useful when using large select queries with JOINS. PARAMETERS
o $result -Array type of the fetched result CUBRID_NUM, CUBRID_ASSOC, CUBRID_BOTH. o $field_offset - The numerical field offset. The $field_offset starts at 0. If $field_offset does not exist, an error of level E_WARNING is also issued. RETURN VALUES
Name of the table of the specified field, on success. FALSE when invalid field_offset value. -1 if SQL sentence is not SELECT. EXAMPLES
Example #1 cubrid_field_table(3) example <?php $conn = cubrid_connect("localhost", 33000, "demodb"); $result = cubrid_execute($conn, "SELECT * FROM code"); $col_num = cubrid_num_cols($result); printf("%-15s %-15s %s ", "Field Table", "Field Name", "Field Type"); for($i = 0; $i < $col_num; $i++) { printf("%-15s %-15s %s ", cubrid_field_table($result, $i), cubrid_field_name($result, $i), cubrid_field_type($result, $i)); } cubrid_disconnect($conn); ?> The above example will output: Field Table Field Name Field Type code s_name char code f_name varchar PHP Documentation Group CUBRID_FIELD_TABLE(3)