Sponsored Content
Full Discussion: converting rows into columns
Top Forums Shell Programming and Scripting converting rows into columns Post 302484684 by svajhala on Sunday 2nd of January 2011 06:40:47 PM
Old 01-02-2011
converting rows into columns

Hi,

I am trying to fetch some values from db and spooling the output to a file.

when i query the db for the values, i get the values in following format.

Code:
PC_1 wf_test1 Test
PC_2 wf_test2 Test
PC_3 wf_test3 Test

But my spool file was created in following format.

Code:
PC_1
wf_test1
Test

PC_2 
wf_test2
Test

PC_3
wf_test3
Test

Now i want to convert the format back to my db format in my spool file. Please let me know how to do it?

-Sam
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to converting rows to columns, bash

I have in file these words: @fraza1 = rw @fraza2 = r @fraza3 = r @fraza4 = r @fraza5 = r @fraza1 = r @fraza6 = r @fraza7 = r @fraza2 = r @fraza8 = r @fraza9 = r ... I would like so that: ,rw,@fraza1 ,r,@fraza2 (2 Replies)
Discussion started by: patrykxes
2 Replies

2. UNIX for Dummies Questions & Answers

Converting rows into multiple-rows

Hi every one; I have a file with 22 rows and 13 columns which includes floating numbers. I want to parse the file so that every five columns in the row would be a new record (row). For example, the first line in the old file should be converted into three lines with first two lines contain 5... (6 Replies)
Discussion started by: PHL
6 Replies

3. UNIX for Dummies Questions & Answers

Converting columns into rows

Is there anyway to convert columns into raws using awk? (or any other command line):eek::eek::eek::eek::eek::eek::eek::eek::eek: (1 Reply)
Discussion started by: cosmologist
1 Replies

4. Shell Programming and Scripting

Converting rows to columns using shell script

I have a script which converts rows to columns. file_name=$1 mailid=$2 #CREATE BACKUP OF ORIGINAL FILE #cp ${file_name}.xlsx ${file_name}_temp.xlsx #tr '\t' '|' < ${file_name}_temp.xlsx > ${file_name}_temp.csv #rm ${file_name}_temp.xlsx pivot_row=`head -1 ${file_name}` sed 1d... (3 Replies)
Discussion started by: andy538
3 Replies

5. Shell Programming and Scripting

Converting rows to columns in csv file

Hi, I have a requirement to convert rows into columns. data looks like: c1,c2,c3,.. r1,r2,r3,.. p1,p2,p3,.. and so on.. output shud be like this: c1,r1,p1,.. c2,r2,p2,.. c3,r3,p3,.. Thanks in advance, (12 Replies)
Discussion started by: Divya1987
12 Replies

6. UNIX for Dummies Questions & Answers

Converting Columns To Rows Sort Of

Hi I'm a UNIX awk and sed novice at best. I'm trying to creat a .csv file so it can be graphed in Excel. Tried various xargs, awk, sed and paste but just can't seem to get the data to line up. Not sure if this is beyond for a question in these forums. Any help would greatly be appreciated. Have... (4 Replies)
Discussion started by: jimmyf
4 Replies

7. UNIX for Dummies Questions & Answers

Converting txt output to rows and columns and send report via mail.

Hi All, I would like to send below output in a tabular column ( xml or excel ) and send a mail. vinay unix anil sql vamsee java request to suggest a solution. (1 Reply)
Discussion started by: Girish19
1 Replies

8. Shell Programming and Scripting

Compare 2 csv files by columns, then extract certain columns of matcing rows

Hi all, I'm pretty much a newbie to UNIX. I would appreciate any help with UNIX coding on comparing two large csv files (greater than 10 GB in size), and output a file with matching columns. I want to compare file1 and file2 by 'id' and 'chain' columns, then extract exact matching rows'... (5 Replies)
Discussion started by: bkane3
5 Replies

9. Shell Programming and Scripting

Converting rows into columns

hi all I need a help ..I have a script that takes has command and its output is like below.. a b a v v a c I am assigning the above outputs to a variable .. <variable name> = <command output> problem here is when I echo the variable ..it gives me output like " a b... (3 Replies)
Discussion started by: shankarb
3 Replies

10. Shell Programming and Scripting

Converting columns of text to rows, with blank lines

I've spent the past hour trying different things and googling for this solution and cannot find the answer. Found variations of this, but not this exact thing. I have the following text, which is the output from our mainframe. Each field is on a separate line, with a blank line between each... (7 Replies)
Discussion started by: lupin..the..3rd
7 Replies
PDOSTATEMENT.FETCHALL(3)						 1						  PDOSTATEMENT.FETCHALL(3)

PDOStatement::fetchAll - Returns an array containing all of the result set rows

SYNOPSIS
public array PDOStatement::fetchAll ([int $fetch_style], [mixed $fetch_argument], [array $ctor_args = array()]) DESCRIPTION
PARAMETERS
o $fetch_style - Controls the contents of the returned array as documented in PDOStatement.fetch(3). Defaults to value of PDO::ATTR_DEFAULT_FETCH_MODE (which defaults to PDO::FETCH_BOTH) To return an array consisting of all values of a single column from the result set, specify PDO::FETCH_COLUMN. You can specify which column you want with the $column-index parameter. To fetch only the unique values of a single column from the result set, bitwise-OR PDO::FETCH_COLUMN with PDO::FETCH_UNIQUE. To return an associative array grouped by the values of a specified column, bitwise-OR PDO::FETCH_COLUMN with PDO::FETCH_GROUP. o $fetch_argument - This argument has a different meaning depending on the value of the $fetch_style parameter: o PDO::FETCH_COLUMN: Returns the indicated 0-indexed column. o PDO::FETCH_CLASS: Returns instances of the specified class, mapping the columns of each row to named properties in the class. o PDO::FETCH_FUNC: Returns the results of calling the specified function, using each row's columns as parameters in the call. o $ctor_args - Arguments of custom class constructor when the $fetch_style parameter is PDO::FETCH_CLASS. RETURN VALUES
PDOStatement.fetchAll(3) returns an array containing all of the remaining rows in the result set. The array represents each row as either an array of column values or an object with properties corresponding to each column name. An empty array is returned if there are zero results to fetch, or FALSE on failure. Using this method to fetch large result sets will result in a heavy demand on system and possibly network resources. Rather than retriev- ing all of the data and manipulating it in PHP, consider using the database server to manipulate the result sets. For example, use the WHERE and ORDER BY clauses in SQL to restrict results before retrieving and processing them with PHP. EXAMPLES
Example #1 Fetch all remaining rows in a result set <?php $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); /* Fetch all of the remaining rows in the result set */ print("Fetch all of the remaining rows in the result set: "); $result = $sth->fetchAll(); print_r($result); ?> The above example will output something similar to: Fetch all of the remaining rows in the result set: Array ( [0] => Array ( [name] => pear [0] => pear [colour] => green [1] => green ) [1] => Array ( [name] => watermelon [0] => watermelon [colour] => pink [1] => pink ) ) Example #2 Fetching all values of a single column from a result set The following example demonstrates how to return all of the values of a single column from a result set, even though the SQL state- ment itself may return multiple columns per row. <?php $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); /* Fetch all of the values of the first column */ $result = $sth->fetchAll(PDO::FETCH_COLUMN, 0); var_dump($result); ?> The above example will output something similar to: Array(3) ( [0] => string(5) => apple [1] => string(4) => pear [2] => string(10) => watermelon ) Example #3 Grouping all values by a single column The following example demonstrates how to return an associative array grouped by the values of the specified column in the result set. The array contains three keys: values apple and pear are returned as arrays that contain two different colours, while water- melon is returned as an array that contains only one colour. <?php $insert = $dbh->prepare("INSERT INTO fruit(name, colour) VALUES (?, ?)"); $insert->execute(array('apple', 'green')); $insert->execute(array('pear', 'yellow')); $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); /* Group values by the first column */ var_dump($sth->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_GROUP)); ?> The above example will output something similar to: array(3) { ["apple"]=> array(2) { [0]=> string(5) "green" [1]=> string(3) "red" } ["pear"]=> array(2) { [0]=> string(5) "green" [1]=> string(6) "yellow" } ["watermelon"]=> array(1) { [0]=> string(5) "green" } } Example #4 Instantiating a class for each result The following example demonstrates the behaviour of the PDO::FETCH_CLASS fetch style. <?php class fruit { public $name; public $colour; } $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); $result = $sth->fetchAll(PDO::FETCH_CLASS, "fruit"); var_dump($result); ?> The above example will output something similar to: array(3) { [0]=> object(fruit)#1(2) { ["name"]=> string(5) "apple" ["colour"]=> string(5) "green" } [1]=> object(fruit)#2(2) { ["name"]=> string(4) "pear" ["colour"]=> string(6) "yellow" } [2]=> object(fruit)#3(2) { ["name"]=> string(10) "watermelon" ["colour"]=> string(4) "pink" } } Example #5 Calling a function for each result The following example demonstrates the behaviour of the PDO::FETCH_FUNC fetch style. <?php function fruit($name, $colour) { return "{$name}: {$colour}"; } $sth = $dbh->prepare("SELECT name, colour FROM fruit"); $sth->execute(); $result = $sth->fetchAll(PDO::FETCH_FUNC, "fruit"); var_dump($result); ?> The above example will output something similar to: array(3) { [0]=> string(12) "apple: green" [1]=> string(12) "pear: yellow" [2]=> string(16) "watermelon: pink" } SEE ALSO
PDO.query(3), PDOStatement.fetch(3), PDOStatement.fetchColumn(3), PDO.prepare(3), PDOStatement.setFetchMode(3). PHP Documentation Group PDOSTATEMENT.FETCHALL(3)
All times are GMT -4. The time now is 04:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy