Sponsored Content
Top Forums Shell Programming and Scripting Match and print columns in second file Post 302628589 by newpro on Monday 23rd of April 2012 06:16:19 PM
Old 04-23-2012
Birei, Kevintse,

Thanks a lot for you help.

-R
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get columns from another file for match in col 2 in 1st file

Hi, My first file has 592155 9 rs16916098 1 592156 19 rs7249604 1 592157 4 rs885156 1 592158 5 rs350067 12nd file has 9 rs16916098 0 113228129 2 4 19 rs7249604 0 58709070 4 2 2 rs17042833 0 113558750 4 2... (2 Replies)
Discussion started by: genehunter
2 Replies

2. Shell Programming and Scripting

Strings from one file which exactly match to the 1st column of other file and then print lines.

Hi, I have two files. 1st file has 1 column (huge file containing ~19200000 lines) and 2nd file has 2 columns (small file containing ~6000 lines). ################################# huge_file.txt a a ab b ################################## small_file.txt a 1.5 b 2.5 ab ... (4 Replies)
Discussion started by: AshwaniSharma09
4 Replies

3. Shell Programming and Scripting

print when column match with other file

Hello all, please help. There are two file like this: file1: 1197510.0 294777.7 9666973.0 21.6 1839.8 1197510.0 294777.7 9666973.0 413.2 2075.9 1197510.0 294777.7 9666973.0 689.3 2260.0 ... (1 Reply)
Discussion started by: attila
1 Replies

4. Shell Programming and Scripting

match two key columns in two files and print output (awk)

I have two files... file1 and file2. Where columns 1 and 2 of file1 match columns 1 and 2 of file2 I want to create a new file that is all file1 + columns 3 and 4 of file2 :b: Many thanks if you know how to do this.... :b: file1 31-101 106 0 92 31-101 106 29 ... (2 Replies)
Discussion started by: pelhabuan
2 Replies

5. Shell Programming and Scripting

Match two columns from two files and print output

Hello, I have two files which are of the following format File 1 which has two columns Protein_ID Substitution NP_997239 T53R NP_060668 V267M NP_058515 P856A NP_001206 T55M NP_006601 D371Y ... (2 Replies)
Discussion started by: nans
2 Replies

6. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns match on two rows

Hi all, I know this sounds suspiciously like a homework course; but, it is not. My goal is to take a file, and match my "ID" column to the "Date" column, if those conditions are true, add the total number of minutes worked and place it in this file, while not printing the original rows that I... (6 Replies)
Discussion started by: mtucker6784
6 Replies

7. UNIX for Advanced & Expert Users

Match and print based on columns

HI, I have 2 different questions in this thread. Consider 2 files as input (input file have different line count ) File 1 1 1 625 56 1 12 657 34 1 9 25 45 1 2 20 54 67 3 25 35 27 4 45 73 36 5 125 56 45 File2 1 1 878 76 1 9 83 67 2 20 73 78 4 47 22 17 3 25 67 99 (4 Replies)
Discussion started by: rossi
4 Replies

8. Shell Programming and Scripting

Match columns and print specific field

Hello, I have data in following format. ... (6 Replies)
Discussion started by: Pushpraj
6 Replies

9. Shell Programming and Scripting

Match Columns in one file and extract columns from another file

Kindly help merging information from two files with the following data structure. I want to match for the CHR-SNP in Foo and get the columns that match from CHROM-rsID Fields 1 & 2 of foo may have duplicates, however, a joint key of Fields $1$2$3$4 is unique. Also would be helpful to clean up... (4 Replies)
Discussion started by: genehunter
4 Replies

10. UNIX for Beginners Questions & Answers

Data match 2 files based on first 2 columns matching only and join if match

Hi, i have 2 files , the data i need to match is in masterfile and i need to pull out column 3 from master if column 1 and 2 match and output entire row to new file I have tried with join and awk and i keep getting blank outputs or same file is there an easier way than what i am... (4 Replies)
Discussion started by: axis88
4 Replies
PDOSTATEMENT.FETCH(3)							 1						     PDOSTATEMENT.FETCH(3)

PDOStatement::fetch - Fetches the next row from a result set

SYNOPSIS
public mixed PDOStatement::fetch ([int $fetch_style], [int $cursor_orientation = PDO::FETCH_ORI_NEXT], [int $cursor_offset]) DESCRIPTION
Fetches a row from a result set associated with a PDOStatement object. The $fetch_style parameter determines how PDO returns the row. PARAMETERS
o $fetch_style - Controls how the next row will be returned to the caller. This value must be one of the PDO::FETCH_* constants, defaulting to value of PDO::ATTR_DEFAULT_FETCH_MODE (which defaults to PDO::FETCH_BOTH). o PDO::FETCH_ASSOC: returns an array indexed by column name as returned in your result set o PDO::FETCH_BOTH (default): returns an array indexed by both column name and 0-indexed column number as returned in your result set o PDO::FETCH_BOUND: returns TRUE and assigns the values of the columns in your result set to the PHP variables to which they were bound with the PDOStatement.bindColumn(3) method o PDO::FETCH_CLASS: returns a new instance of the requested class, mapping the columns of the result set to named properties in the class. If $fetch_style includes PDO::FETCH_CLASSTYPE (e.g. PDO::FETCH_CLASS | PDO::FETCH_CLASSTYPE) then the name of the class is determined from a value of the first column. o PDO::FETCH_INTO: updates an existing instance of the requested class, mapping the columns of the result set to named prop- erties in the class o PDO::FETCH_LAZY: combines PDO::FETCH_BOTH and PDO::FETCH_OBJ, creating the object variable names as they are accessed o PDO::FETCH_NAMED: returns an array with the same form as PDO::FETCH_ASSOC, except that if there are multiple columns with the same name, the value referred to by that key will be an array of all the values in the row that had that column name o PDO::FETCH_NUM: returns an array indexed by column number as returned in your result set, starting at column 0 o PDO::FETCH_OBJ: returns an anonymous object with property names that correspond to the column names returned in your result set o $cursor_orientation - For a PDOStatement object representing a scrollable cursor, this value determines which row will be returned to the caller. This value must be one of the PDO::FETCH_ORI_* constants, defaulting to PDO::FETCH_ORI_NEXT. To request a scrollable cursor for your PDOStatement object, you must set the PDO::ATTR_CURSOR attribute to PDO::CURSOR_SCROLL when you prepare the SQL statement with PDO.prepare(3). o $offset - For a PDOStatement object representing a scrollable cursor for which the cursor_orientation parameter is set to PDO::FETCH_ORI_ABS, this value specifies the absolute number of the row in the result set that shall be fetched. For a PDOState- ment object representing a scrollable cursor for which the cursor_orientation parameter is set to PDO::FETCH_ORI_REL, this value specifies the row to fetch relative to the cursor position before PDOStatement.fetch(3) was called. RETURN VALUES
The return value of this function on success depends on the fetch type. In all cases, FALSE is returned on failure. EXAMPLES
Example #1 Fetching rows using different fetch styles <?php $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); /* Exercise PDOStatement::fetch styles */ print("PDO::FETCH_ASSOC: "); print("Return next row as an array indexed by column name "); $result = $sth->fetch(PDO::FETCH_ASSOC); print_r($result); print(" "); print("PDO::FETCH_BOTH: "); print("Return next row as an array indexed by both column name and number "); $result = $sth->fetch(PDO::FETCH_BOTH); print_r($result); print(" "); print("PDO::FETCH_LAZY: "); print("Return next row as an anonymous object with column names as properties "); $result = $sth->fetch(PDO::FETCH_LAZY); print_r($result); print(" "); print("PDO::FETCH_OBJ: "); print("Return next row as an anonymous object with column names as properties "); $result = $sth->fetch(PDO::FETCH_OBJ); print $result->name; print(" "); ?> The above example will output: PDO::FETCH_ASSOC: Return next row as an array indexed by column name Array ( [name] => apple [colour] => red ) PDO::FETCH_BOTH: Return next row as an array indexed by both column name and number Array ( [name] => banana [0] => banana [colour] => yellow [1] => yellow ) PDO::FETCH_LAZY: Return next row as an anonymous object with column names as properties PDORow Object ( [name] => orange [colour] => orange ) PDO::FETCH_OBJ: Return next row as an anonymous object with column names as properties kiwi Example #2 Fetching rows with a scrollable cursor <?php function readDataForwards($dbh) { $sql = 'SELECT hand, won, bet FROM mynumbers ORDER BY BET'; try { $stmt = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); $stmt->execute(); while ($row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) { $data = $row[0] . " " . $row[1] . " " . $row[2] . " "; print $data; } $stmt = null; } catch (PDOException $e) { print $e->getMessage(); } } function readDataBackwards($dbh) { $sql = 'SELECT hand, won, bet FROM mynumbers ORDER BY bet'; try { $stmt = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL)); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_LAST); do { $data = $row[0] . " " . $row[1] . " " . $row[2] . " "; print $data; } while ($row = $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_PRIOR)); $stmt = null; } catch (PDOException $e) { print $e->getMessage(); } } print "Reading forwards: "; readDataForwards($conn); print "Reading backwards: "; readDataBackwards($conn); ?> The above example will output: Reading forwards: 21 10 5 16 0 5 19 20 10 Reading backwards: 19 20 10 16 0 5 21 10 5 SEE ALSO
PDO.prepare(3), PDOStatement.execute(3), PDOStatement.fetchAll(3), PDOStatement.fetchColumn(3), PDOStatement.fetchObject(3), PDOState- ment.setFetchMode(3). PHP Documentation Group PDOSTATEMENT.FETCH(3)
All times are GMT -4. The time now is 10:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy