Sponsored Content
Full Discussion: Inconsistent column printing
Top Forums Shell Programming and Scripting Inconsistent column printing Post 302801055 by jacobs.smith on Wednesday 1st of May 2013 08:31:59 AM
Old 05-01-2013
Quote:
Originally Posted by clx
You are printing "v" inside the for loop. Which means printing

Code:
col1 .. col8 col9
col1 .. col8 col10
col1 .. col8 col11
..
..

And repeat the same for next row.
Is that you really want?

May be you need this?
Code:
awk '{v=$1"\t"$4"\t"$5"\t"$2"\t"$3"\t"$6"\t"$7"\t"$8; printf v;{for(i=9;i<=NF;++i)printf "\t"$i}print x}' input

Thanks for your time clx.

It does what I needed. But, from col1 to col8 I want the field separator to be tab. And from col9 till the end, I would just like to print as it is in the input.

---------- Post updated at 08:31 AM ---------- Previous update was at 08:29 AM ----------

Quote:
Originally Posted by RudiC
Code:
$ awk '{X=$4; Y=$5; $4=$2; $5=$3; $2=X; $3=Y}1' OFS="\t" file

Thanks Rudic, I tried taking of the OFS, but it makes all columns to be space separated.

Is there a way to print col1 to col8 in tabs and then from col9 till the end as it is from the input?

Thanks
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Printing highest value from one column

Hi, I have a file that looks like this: s6 98 s6 91 s6 56 s5 32 s5 10 s5 4 So what I want to do is print only the highest value for each value in the column: So the file will look like this: s6 98 s5 32 Thanks (4 Replies)
Discussion started by: phil_heath
4 Replies

2. Shell Programming and Scripting

regarding about printing row to column

Hello, I got data like that, =111 A= alpha B= 1 C= qq D= 45 F= ss G= 334 =1234 A= B= 2w C= D= 443 F= G= =3434 A= B= e3e (5 Replies)
Discussion started by: davidkhan
5 Replies

3. UNIX for Dummies Questions & Answers

creating a file using the fist column and printing second column

Hello all. I have a problem that I need help solving. I would like to convert the following file: human pool1_12 10e-02 45 67 human pool1_1899 10e-01 45 29 human pool1_1829 10e-01 43 26 horse pool1_343 10e-20 65 191 horse pool1_454 10e-09 44 43... (5 Replies)
Discussion started by: viralnerd
5 Replies

4. Solaris

Printing a particular column[autosys]

Dear All, I'm using autosys in my production system. My concern is as follows: autosys -j <some_job_nm> Output: Job Name Last Start Last End ST Run Pri/Xit ... (1 Reply)
Discussion started by: saps19
1 Replies

5. UNIX for Dummies Questions & Answers

Printing a particular column using SED

Hi, i want to display only the particular column using SED command. For example, ps -ef|grep ash |sed -n '1p'|cut -d ' ' -f2   this gives 29067 ps -ef|grep ash |sed -n '1p'|awk '{print $2}'    this also gives the same  in the same way i need the solution using sed. Please... (4 Replies)
Discussion started by: pandeesh
4 Replies

6. Shell Programming and Scripting

Printing second column of several files into one

HI All, I have exactly 100 text files with extension .txt. The files contain numbers like this: 1.txt 0.4599994 65914 0.40706193 190743 0.39977244 185019 0.39831382 74906 0.3915928 122428 0.38844505 39999 0.38820446 72691 0.38787442 176430 0.38670844 28791 0.38597047 91091... (2 Replies)
Discussion started by: shoaibjameel123
2 Replies

7. Shell Programming and Scripting

Column printing in awk

Experts, i have a following file containing data in following manner. 1 2480434.4 885618.6 0.00 1948.00 40.00 1952.00 ... (6 Replies)
Discussion started by: Amit.saini333
6 Replies

8. Shell Programming and Scripting

printing certain elelment of a column

"File1.txt" CHR SNP BP ANNOT 8 rs1878374 127974042 MYC(-843.5kb)|FAM84B(+334.4kb) 2 rs2042077 16883103 VSNL1(-702.2kb)|SMC6(-825.5kb)|RAD51AP2(-672.4kb)|MYCN(+878.5kb)|MSGN1(-978.2kb)|GEN1(-915.6kb)|FAM49A(+172.5kb) 12 rs10431347 3023955... (4 Replies)
Discussion started by: johnkim0806
4 Replies

9. UNIX for Dummies Questions & Answers

Printing out lines that have the same value in the first column but different value in the second

Hi, I have a text file that looks like the following: ILMN_1343291 6 74341083 74341772 ILMN_1343291 6 74341195 74341099 ILMN_1343295 12 6387581 6387650 ILMN_1651209 1 1657001 1657050 ILMN_1651209 5 83524260 83524309 I... (1 Reply)
Discussion started by: evelibertine
1 Replies

10. Shell Programming and Scripting

Inconsistent behavior when sorting by column

I'm trying to sort the list below, so that multiple instances of the form pass=i_d=j are contiguous. Curiously, the standard sort command to do this works some of the time (it produced the output below) but not all of the time. the command I used was cat fileName | sort -k1.26,1.26n... (3 Replies)
Discussion started by: LeoKSimon
3 Replies
OCI_EXECUTE(3)															    OCI_EXECUTE(3)

oci_execute - Executes a statement

SYNOPSIS
bool oci_execute (resource $statement, [int $mode = OCI_COMMIT_ON_SUCCESS]) DESCRIPTION
Executes a $statement previously returned from oci_parse(3). After execution, statements like INSERT will have data committed to the database by default. For statements like SELECT, execution per- forms the logic of the query. Query results can subsequently be fetched in PHP with functions like oci_fetch_array(3). Each parsed statement may be executed multiple times, saving the cost of re-parsing. This is commonly used for INSERT statements when data is bound with oci_bind_by_name(3). PARAMETERS
o $statement - A valid OCI statement identifier. o $mode - An optional second parameter can be one of the following constants: Execution Modes +----------------------+---------------------------------------------------+ | Constant | | | | | | | Description | | | | +----------------------+---------------------------------------------------+ | | | |OCI_COMMIT_ON_SUCCESS | | | | | | | Automatically commit all outstanding changes for | | | this connection when the statement has succeeded. | | | This is the default. | | | | | | | | OCI_DESCRIBE_ONLY | | | | | | | Make query meta data available to functions like | | | oci_field_name(3) but do not create a result set. | | | Any subsequent fetch call such as | | | oci_fetch_array(3) will fail. | | | | | | | | OCI_NO_AUTO_COMMIT | | | | | | | Do not automatically commit changes. Prior to PHP | | | 5.3.2 (PECL OCI8 1.4) use OCI_DEFAULT which is | | | equivalent to OCI_NO_AUTO_COMMIT. | | | | +----------------------+---------------------------------------------------+ Using OCI_NO_AUTO_COMMIT mode starts or continues a transaction. Transactions are automatically rolled back when the connection is closed, or when the script ends. Explicitly call oci_commit(3) to commit a transaction, or oci_rollback(3) to abort it. When inserting or updating data, using transactions is recommended for relational data consistency and for performance reasons. If OCI_NO_AUTO_COMMIT mode is used for any statement including queries, and oci_commit(3) or oci_rollback(3) is not subsequently called, then OCI8 will perform a rollback at the end of the script even if no data was changed. To avoid an unnecessary rollback, many scripts do not use OCI_NO_AUTO_COMMIT mode for queries or PL/SQL. Be careful to ensure the appropriate transactional consis- tency for the application when using oci_execute(3) with different modes in the same script. RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 oci_execute(3) for queries <?php $conn = oci_connect('hr', 'welcome', 'localhost/XE'); $stid = oci_parse($conn, 'SELECT * FROM employees'); oci_execute($stid); echo "<table border='1'> "; while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) { echo "<tr> "; foreach ($row as $item) { echo " <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td> "; } echo "</tr> "; } echo "</table> "; ?> Example #2 oci_execute(3) without specifying a mode example <?php // Before running, create the table: // CREATE TABLE MYTABLE (col1 NUMBER); $conn = oci_connect('hr', 'welcome', 'localhost/XE'); $stid = oci_parse($conn, 'INSERT INTO mytab (col1) VALUES (123)'); oci_execute($stid); // The row is committed and immediately visible to other users ?> Example #3 oci_execute(3) with OCI_NO_AUTO_COMMIT example <?php // Before running, create the table: // CREATE TABLE MYTABLE (col1 NUMBER); $conn = oci_connect('hr', 'welcome', 'localhost/XE'); $stid = oci_parse($conn, 'INSERT INTO mytab (col1) VALUES (:bv)'); oci_bind_by_name($stid, ':bv', $i, 10); for ($i = 1; $i <= 5; ++$i) { oci_execute($stid, OCI_NO_AUTO_COMMIT); // use OCI_DEFAULT for PHP <= 5.3.1 } oci_commit($conn); // commits all new values: 1, 2, 3, 4, 5 ?> Example #4 oci_execute(3) with different commit modes example <?php // Before running, create the table: // CREATE TABLE MYTABLE (col1 NUMBER); $conn = oci_connect('hr', 'welcome', 'localhost/XE'); $stid = oci_parse($conn, 'INSERT INTO mytab (col1) VALUES (123)'); oci_execute($stid, OCI_NO_AUTO_COMMIT); // data not committed $stid = oci_parse($conn, 'INSERT INTO mytab (col1) VALUES (456)'); oci_execute($stid); // commits both 123 and 456 values ?> Example #5 oci_execute(3) with OCI_DESCRIBE_ONLY example <?php $conn = oci_connect('hr', 'welcome', 'localhost/XE'); $stid = oci_parse($conn, 'SELECT * FROM locations'); oci_execute($s, OCI_DESCRIBE_ONLY); for ($i = 1; $i <= oci_num_fields($stid); ++$i) { echo oci_field_name($stid, $i) . "<br> "; } ?> NOTES
Note Transactions are automatically rolled back when connections are closed, or when the script ends, whichever is soonest. Explicitly call oci_commit(3) to commit a transaction. Any call to oci_execute(3) that uses OCI_COMMIT_ON_SUCCESS mode explicitly or by default will commit any previous uncommitted transaction. Any Oracle DDL statement such as CREATE or DROP will automatically commit any uncommitted transaction. Note Because the oci_execute(3) function generally sends the statement to the database, oci_execute(3) can identify some statement syn- tax errors that the lightweight, local oci_parse(3) function does not. SEE ALSO
oci_parse(3). PHP Documentation Group OCI_EXECUTE(3)
All times are GMT -4. The time now is 05:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy