Sponsored Content
Top Forums Shell Programming and Scripting Compare two variables and print the difference Post 303037552 by amar1208 on Monday 5th of August 2019 02:46:26 PM
Old 08-05-2019
i am getting error as below
Code:
tat.sh: line 33: {0..8}: syntax error: operand expected (error token is "{0..8}")
================================================================
below is my entire shell scrip and output of it when i run

PRIM_SEQ=`sqlplus -s "/ as sysdba" <<EOF
set heading off feedback off verify off
select max(sequence#) from gv\\$log group by thread#;
exit
EOF`
echo "====================================="
echo "PRIMARY_SEQUENCE of" DB_UNIQUE_NAME
echo "====================================="
echo $PRIM_SEQ
echo ""
STDBY_SEQ=`sqlplus -s sys/nobody@stdby as sysdba <<EOF
set heading off feedback off verify off
select max(sequence#) from gv\\$log group by thread#;
exit
EOF`
echo "====================================="
echo "STANDBY_SEQUENCE of DB" 
echo "====================================="
echo $STDBY_SEQ
echo ""
echo
for i in {0..${#PRIM_SEQ}}
do
   [[ -n "${PRIM_SEQ[i]}" && -n "${STB_SEQ[i]}" ]] && {
      (( x = PRIM_SEQ[$i] - STB_SEQ[$i] ))
      echo $x
   }
done


sh tat.sh

=====================================
PRIMARY_SEQUENCE of
=====================================
12072
11728

=====================================
STANDBY_SEQUENCE of
=====================================
12070
11700

tat.sh: line 33: {0..8}: syntax error: operand expected (error token is "{0..8}")


Last edited by RavinderSingh13; 08-05-2019 at 10:53 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

compare 2 file and print difference in the third file URG PLS

Hi I have two files in unix. I need to compare two files and print the differed lines in other file Eg file1 1111 2222 3333 file2 1111 2222 3333 4444 5555 newfile 4444 5555 Thanks In advance (3 Replies)
Discussion started by: evvander
3 Replies

2. Shell Programming and Scripting

to compare two files and to print the difference

suppose one file P1168S P2150L P85L Q597R R1097C Another file P2150L P85L Q597R R1097C R1379C R1587K Then output shud be R1379C R1587K thanks (5 Replies)
Discussion started by: cdfd123
5 Replies

3. Shell Programming and Scripting

Compare difference

Hi every body Help required file 1 aaaaa bbbb cccccc dddd ffff File 2 aaaaa,1,ee,44,5t,6y, cccccc, ..... dddd, ..... eeeeee, ..... ffff, ...... ggg, ....... (7 Replies)
Discussion started by: The_Archer
7 Replies

4. Shell Programming and Scripting

Compare two files and print the two lines with difference

I have two files like this: #FILE 1 ABCD 4322 26485 JMTJ 5311 97248 XMPJ 4321 58978 #FILE 2 ABCD 4321 26485 JMTJ 5311 97248 XMPJ 4321 68978 What to do: Compare the two files and find those lines that doesn't match. And have a new file like this: #FILE 3 "from file 1" ABCD 4322 26485... (11 Replies)
Discussion started by: kingpeejay
11 Replies

5. Shell Programming and Scripting

Compare selected columns from a file and print difference

I have learned file comparison from my previous post here. Then, it is comparing the whole line. Now, i have a new problem. I have two files with 3 columns separated with a "|". What i want to do is to compare the second and third column of file 1, and the second and third column of file 2. And... (4 Replies)
Discussion started by: kingpeejay
4 Replies

6. Shell Programming and Scripting

Compare two columns in two files and print the difference

one file . . importing table employee 119 . . importing table jobs 1 2nd file . . importing table employee 120 . . importing table jobs 1 and would like... (2 Replies)
Discussion started by: jhonnyrip
2 Replies

7. UNIX for Dummies Questions & Answers

compare / difference between sub-sections of files

Hi there, I'm sure this question has been asked many times but I can't find any posts with information. How can I check the differences between say lines 20 - 200 in file1 and lines 420 - 600 in file2? Thanks in advance for any help! js (2 Replies)
Discussion started by: js8765
2 Replies

8. Shell Programming and Scripting

Compare file1 for matching line in file2 and print the difference in matching lines

Hello, I have two files file 1 and file 2 each having result of a query on certain database tables and need to compare for Col1 in file1 with Col3 in file2, compare Col2 with Col4 and output the value of Col1 from File1 which is a) not present in Col3 of File2 b) value of Col2 is different from... (2 Replies)
Discussion started by: RasB15
2 Replies

9. Shell Programming and Scripting

Simple awk command to compare two files and print first difference

Hello, I have two text files, each with a single column, file 1: 124152970 123899868 123476854 54258288 123117283 file 2: 124152970 123899868 54258288 123117283 122108330 (5 Replies)
Discussion started by: LMHmedchem
5 Replies

10. UNIX for Beginners Questions & Answers

Compare two variables and print the difference

compare two variables and print the difference i have two variables X1=rac1,rac2 Y1=rac2,rac3 output=rac1,rac3 Use code tags to wrap code fragments or data samples. (1 Reply)
Discussion started by: jhonnyrip
1 Replies
DB2_BIND_PARAM(3)							 1							 DB2_BIND_PARAM(3)

db2_bind_param - Binds a PHP variable to an SQL statement parameter

SYNOPSIS
bool db2_bind_param (resource $stmt, int $parameter-number, string $variable-name, [int $parameter-type], [int $data-type], [int $precision = -1], [int $scale]) DESCRIPTION
Binds a PHP variable to an SQL statement parameter in a statement resource returned by db2_prepare(3). This function gives you more con- trol over the parameter type, data type, precision, and scale for the parameter than simply passing the variable as part of the optional input array to db2_execute(3). PARAMETERS
o $stmt - A prepared statement returned from db2_prepare(3). o $parameter-number - Specifies the 1-indexed position of the parameter in the prepared statement. o $variable-name - A string specifying the name of the PHP variable to bind to the parameter specified by $parameter-number. o $parameter-type - A constant specifying whether the PHP variable should be bound to the SQL parameter as an input parameter ( DB2_PARAM_IN), an output parameter ( DB2_PARAM_OUT), or as a parameter that accepts input and returns output ( DB2_PARAM_INOUT). To avoid memory overhead, you can also specify DB2_PARAM_FILE to bind the PHP variable to the name of a file that contains large object (BLOB, CLOB, or DBCLOB) data. o $data-type - A constant specifying the SQL data type that the PHP variable should be bound as: one of DB2_BINARY, DB2_CHAR, DB2_DOUBLE, or DB2_LONG . o $precision - Specifies the precision with which the variable should be bound to the database. This parameter can also be used for retrieving XML output values from stored procedures. A non-negative value specifies the maximum size of the XML data that will be retrieved from the database. If this parameter is not used, a default of 1MB will be assumed for retrieving the XML output value from the stored procedure. o $scale - Specifies the scale with which the variable should be bound to the database. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 Binding PHP variables to a prepared statement The SQL statement in the following example uses two input parameters in the WHERE clause. We call db2_bind_param(3) to bind two PHP variables to the corresponding SQL parameters. Notice that the PHP variables do not have to be declared or assigned before the call to db2_bind_param(3); in the example, $lower_limit is assigned a value before the call to db2_bind_param(3), but $upper_limit is assigned a value after the call to db2_bind_param(3). The variables must be bound and, for parameters that accept input, must have any value assigned, before calling db2_execute(3). <?php $sql = 'SELECT name, breed, weight FROM animals WHERE weight > ? AND weight < ?'; $conn = db2_connect($database, $user, $password); $stmt = db2_prepare($conn, $sql); // We can declare the variable before calling db2_bind_param() $lower_limit = 1; db2_bind_param($stmt, 1, "lower_limit", DB2_PARAM_IN); db2_bind_param($stmt, 2, "upper_limit", DB2_PARAM_IN); // We can also declare the variable after calling db2_bind_param() $upper_limit = 15.0; if (db2_execute($stmt)) { while ($row = db2_fetch_array($stmt)) { print "{$row[0]}, {$row[1]}, {$row[2]} "; } } ?> The above example will output: Pook, cat, 3.2 Rickety Ride, goat, 9.7 Peaches, dog, 12.3 Example #2 Calling stored procedures with IN and OUT parameters The stored procedure match_animal in the following example accepts three different parameters: o an input (IN) parameter that accepts the name of the first animal as input o an input-output (INOUT) parameter that accepts the name of the second animal as input and returns the string TRUE if an animal in the database matches that name o an output (OUT) parameter that returns the sum of the weight of the two identified animals In addition, the stored procedure returns a result set consisting of the animals listed in alphabetic order starting at the animal corresponding to the input value of the first parameter and ending at the animal corresponding to the input value of the second parameter. <?php $sql = 'CALL match_animal(?, ?, ?)'; $conn = db2_connect($database, $user, $password); $stmt = db2_prepare($conn, $sql); $name = "Peaches"; $second_name = "Rickety Ride"; $weight = 0; db2_bind_param($stmt, 1, "name", DB2_PARAM_IN); db2_bind_param($stmt, 2, "second_name", DB2_PARAM_INOUT); db2_bind_param($stmt, 3, "weight", DB2_PARAM_OUT); print "Values of bound parameters _before_ CALL: "; print " 1: {$name} 2: {$second_name} 3: {$weight} "; if (db2_execute($stmt)) { print "Values of bound parameters _after_ CALL: "; print " 1: {$name} 2: {$second_name} 3: {$weight} "; print "Results: "; while ($row = db2_fetch_array($stmt)) { print " {$row[0]}, {$row[1]}, {$row[2]} "; } } ?> The above example will output: Values of bound parameters _before_ CALL: 1: Peaches 2: Rickety Ride 3: 0 Values of bound parameters _after_ CALL: 1: Peaches 2: TRUE 3: 22 Results: Peaches, dog, 12.3 Pook, cat, 3.2 Rickety Ride, goat, 9.7 Example #3 Inserting a binary large object (BLOB) directly from a file The data for large objects are typically stored in files, such as XML documents or audio files. Rather than reading an entire file into a PHP variable, and then binding that PHP variable into an SQL statement, you can avoid some memory overhead by binding the file directly to the input parameter of your SQL statement. The following example demonstrates how to bind a file directly into a BLOB column. <?php $stmt = db2_prepare($conn, "INSERT INTO animal_pictures(picture) VALUES (?)"); $picture = "/opt/albums/spook/grooming.jpg"; $rc = db2_bind_param($stmt, 1, "picture", DB2_PARAM_FILE); $rc = db2_execute($stmt); ?> SEE ALSO
db2_execute(3), db2_prepare(3). PHP Documentation Group DB2_BIND_PARAM(3)
All times are GMT -4. The time now is 04:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy