Sponsored Content
Full Discussion: First Occurence
Top Forums UNIX for Advanced & Expert Users First Occurence Post 302094636 by kkm_job on Monday 30th of October 2006 04:28:03 PM
Old 10-30-2006
First Occurence

Hi,
This is the format of the file that i have
StartDate:10/01/06
EndDate :10/02/06

Cno Ccode
1 10
2 11


StartDate:10/03/06
EndDate :10/04/06

Cno Ccode
2 13
4 12


StartDate:10/01/06
EndDate :10/02/06

Cno Ccode
3 10
2 15




I need the first occurence of startdate and end date in a seperate file...
So the new file should have a row with values of
10/01/06,10/02/06


Can some help me writing the script


Thanks
Kiran
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

grep for certain occurence

I am using grep to pull out info from a file. The line I am searching for begins: START TIME - Tue Sep 11 16:40:00. There are mutiple lines of START TIME. I need the FIRST occurence ONLY. My grep is as follows: start="$( grep 'START TIME' filename | cut -c15-33)" If I echo or cat... (2 Replies)
Discussion started by: app4dxh
2 Replies

2. UNIX for Dummies Questions & Answers

grep the last occurence

is there a grep or awk one-line command to print the line of the last occurence of a string in a file? (3 Replies)
Discussion started by: apalex
3 Replies

3. Shell Programming and Scripting

Extracting the last occurence

Hi All, Is there any awk or unix command that i can make use such that the output will be as desired ? The code will extract the latest pattern starting from the term above the asterix till the end of the input Input: ******** aaa bbb 2007 ******** 123 234 134 ******** xxx yyy 2007... (9 Replies)
Discussion started by: Raynon
9 Replies

4. UNIX for Dummies Questions & Answers

First occurence from grep

Hi , supoose i have a file in which a word is repeated so many times. I just want the firts occurence of that word through grep and it should not go to the next one means get the first occurence and stop there. Suggest me some solutions. Thanks Namish (10 Replies)
Discussion started by: namishtiwari
10 Replies

5. UNIX for Dummies Questions & Answers

Only one particular occurence needs to be substituted !!!

In a file, field separetor in line is irregular number of spaces, so I canot use field in sub function to get my charecter replaced with empty space. I would like to substitute only one perticular charecter with space at perticular posiotn, so I canot use perticular character as that may occur... (6 Replies)
Discussion started by: vaka
6 Replies

6. Shell Programming and Scripting

Change first occurence

I'm not getting the syntax correct to change a line only on the first occurrence: I've tried to change only the first match and I've tried to change the from the second match forward sed 's/<B>PT#/<tr><td class=\"pt1\" width=\"40%\"><B>pt#/1' $file > tmpfile.html sed ... (0 Replies)
Discussion started by: dba_frog
0 Replies

7. UNIX for Dummies Questions & Answers

How to print first occurence

Hi there, how can i print the first pattern occurrence in a .log file? I want to print the filename of the first 17262? I tried but all I can do is print all the lines with the number 17262? I tried using awk and sed but nothing!:wall: I just want filename! Here´s an example: 17259... (3 Replies)
Discussion started by: BMatter
3 Replies

8. Shell Programming and Scripting

Percentage of occurence

Dear all, I have data like below and i need to add coloumn before the COUNT field to see the Percentage out of all COUNT field value for respective raw. ============================================= COUNT CODE sConnType tConnType... (6 Replies)
Discussion started by: Iroshan
6 Replies

9. Shell Programming and Scripting

Print between patterns - first occurence, second occurence etc

I have a file # cat asasas AAAAAA 11 22 33 44 BBBBB NILNILNIL AAAAAA 22 33 44 55 66 77 88 BBBBB NILNILNIL (2 Replies)
Discussion started by: anil510
2 Replies

10. UNIX for Advanced & Expert Users

Get the first occurence between two patterns

I have an output file which gives me the timely status of a server. Sample file: March 11 2014 21:10, 1, 2, 3, 4, 5, 6, 7, 8, 9, x, y, z... 21:05, 1, 2, 3, 4, 5, 6, 7, 8, 9, x, y, z... 21:00, 1, 2, 3, 4,... (3 Replies)
Discussion started by: rpm120
3 Replies
DB2_EXECUTE(3)								 1							    DB2_EXECUTE(3)

db2_execute - Executes a prepared SQL statement

SYNOPSIS
bool db2_execute (resource $stmt, [array $parameters]) DESCRIPTION
db2_execute(3) executes an SQL statement that was prepared by db2_prepare(3). If the SQL statement returns a result set, for example, a SELECT statement or a CALL to a stored procedure that returns one or more result sets, you can retrieve a row as an array from the stmt resource using db2_fetch_assoc(3), db2_fetch_both(3), or db2_fetch_array(3). Alter- natively, you can use db2_fetch_row(3) to move the result set pointer to the next row and fetch a column at a time from that row with db2_result(3). Refer to db2_prepare(3) for a brief discussion of the advantages of using db2_prepare(3) and db2_execute(3) rather than db2_exec(3). PARAMETERS
o $stmt - A prepared statement returned from db2_prepare(3). o $parameters - An array of input parameters matching any parameter markers contained in the prepared statement. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 Preparing and executing an SQL statement with parameter markers The following example prepares an INSERT statement that accepts four parameter markers, then iterates over an array of arrays con- taining the input values to be passed to db2_execute(3). <?php $pet = array(0, 'cat', 'Pook', 3.2); $insert = 'INSERT INTO animals (id, breed, name, weight) VALUES (?, ?, ?, ?)'; $stmt = db2_prepare($conn, $insert); if ($stmt) { $result = db2_execute($stmt, $pet); if ($result) { print "Successfully added new pet."; } } ?> The above example will output: Successfully added new pet. Example #2 Calling a stored procedure with an OUT parameter The following example prepares a CALL statement that accepts one parameter marker representing an OUT parameter, binds the PHP variable $my_pets to the parameter using db2_bind_param(3), then issues db2_execute(3) to execute the CALL statement. After the CALL to the stored procedure has been made, the value of $num_pets changes to reflect the value returned by the stored procedure for that OUT parameter. <?php $num_pets = 0; $res = db2_prepare($conn, "CALL count_my_pets(?)"); $rc = db2_bind_param($res, 1, "num_pets", DB2_PARAM_OUT); $rc = db2_execute($res); print "I have $num_pets pets!"; ?> The above example will output: I have 7 pets! Example #3 Returning XML data as an SQL ResultSet The following example demonstrates how to work with documents stored in a XML column using the SAMPLE database. Using some pretty simple SQL/XML, this example returns some of the nodes in a XML document in an SQL ResultSet format that most users are familiar with. <?php $conn = db2_connect("SAMPLE", "db2inst1", "ibmdb2"); $query = 'SELECT * FROM XMLTABLE( XMLNAMESPACES (DEFAULT 'http://posample.org'), 'db2-fn:xmlcolumn("CUSTOMER.INFO")/customerinfo' COLUMNS "CID" VARCHAR (50) PATH '@Cid', "NAME" VARCHAR (50) PATH 'name', "PHONE" VARCHAR (50) PATH 'phone [ @type = "work"]' ) AS T WHERE NAME = ? '; $stmt = db2_prepare($conn, $query); $name = 'Kathy Smith'; if ($stmt) { db2_bind_param($stmt, 1, "name", DB2_PARAM_IN); db2_execute($stmt); while($row = db2_fetch_object($stmt)){ printf("$row->CID $row->NAME $row->PHONE "); } } db2_close($conn); ?> The above example will output: 1000 Kathy Smith 416-555-1358 1001 Kathy Smith 905-555-7258 Example #4 Performing a "JOIN" with XML data The following example works with documents stored in 2 different XML columns in the SAMPLE database. It creates 2 temporary tables from the XML documents from 2 different columns and returns an SQL ResultSet with information regarding shipping status for the cus- tomer. <?php $conn = db2_connect("SAMPLE", "db2inst1", "ibmdb2"); $query = ' SELECT A.CID, A.NAME, A.PHONE, C.PONUM, C.STATUS FROM XMLTABLE( XMLNAMESPACES (DEFAULT 'http://posample.org'), 'db2-fn:xmlcolumn("CUSTOMER.INFO")/customerinfo' COLUMNS "CID" BIGINT PATH '@Cid', "NAME" VARCHAR (50) PATH 'name', "PHONE" VARCHAR (50) PATH 'phone [ @type = "work"]' ) as A, PURCHASEORDER AS B, XMLTABLE ( XMLNAMESPACES (DEFAULT 'http://posample.org'), 'db2-fn:xmlcolumn("PURCHASEORDER.PORDER")/PurchaseOrder' COLUMNS "PONUM" BIGINT PATH '@PoNum', "STATUS" VARCHAR (50) PATH '@Status' ) as C WHERE A.CID = B.CUSTID AND B.POID = C.PONUM AND A.NAME = ? $stmt = db2_prepare($conn, $query); $name = 'Kathy Smith'; if ($stmt) { db2_bind_param($stmt, 1, "name", DB2_PARAM_IN); db2_execute($stmt); while($row = db2_fetch_object($stmt)){ printf("$row->CID $row->NAME $row->PHONE $row->PONUM $row->STATUS "); } } db2_close($conn); ?> The above example will output: 1001 Kathy Smith 905-555-7258 5002 Shipped Example #5 Returning SQL data as part of a larger XML document The following example works with a portion of the PRODUCT.DESCRIPTION documents in the SAMPLE database. It creates a XML document containing product description (XML data) and pricing info (SQL data). <?php $conn = db2_connect("SAMPLE", "db2inst1", "ibmdb2"); $query = ' SELECT XMLSERIALIZE( XMLQUERY(' declare boundary-space strip; declare default element namespace "http://posample.org"; <promoList> { for $prod in $doc/product where $prod/description/price < 10.00 order by $prod/description/price ascending return( <promoitem> { $prod, <startdate> {$start} </startdate>, <enddate> {$end} </enddate>, <promoprice> {$promo} </promoprice> } </promoitem> ) } </promoList> ' passing by ref DESCRIPTION AS "doc", PROMOSTART as "start", PROMOEND as "end", PROMOPRICE as "promo" RETURNING SEQUENCE) AS CLOB (32000)) AS NEW_PRODUCT_INFO FROM PRODUCT WHERE PID = ? $stmt = db2_prepare($conn, $query); $pid = "100-100-01"; if ($stmt) { db2_bind_param($stmt, 1, "pid", DB2_PARAM_IN); db2_execute($stmt); while($row = db2_fetch_array($stmt)){ printf("$row[0] "); } } db2_close($conn); ?> The above example will output: <promoList xmlns="http://posample.org"> <promoitem> <product pid="100-100-01"> <description> <name>Snow Shovel, Basic 22 inch</name> <details>Basic Snow Shovel, 22 inches wide, straight handle with D-Grip</details> <price>9.99</price> <weight>1 kg</weight> </description> </product> <startdate>2004-11-19</startdate> <enddate>2004-12-19</enddate> <promoprice>7.25</promoprice> </promoitem> </promoList> SEE ALSO
db2_exec(3), db2_fetch_array(3), db2_fetch_assoc(3), db2_fetch_both(3), db2_fetch_row(3), db2_prepare(3), db2_result(3). PHP Documentation Group DB2_EXECUTE(3)
All times are GMT -4. The time now is 05:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy