Home » Infrastructure » Unix » How to place a tab delimiter in output file
How to place a tab delimiter in output file [message #110943] Fri, 11 March 2005 05:45 Go to next message
Naveen Verma
Messages: 60
Registered: August 2004
Member
Hi
My script fetches data from the database and writes the ouptut to a flat file.My requirement is that the output should be delimited by tab in between columns.
Could anyone help me to sort out this problem.

Thanks and Regards
Naveen
Re: How to place a tab delimiter in output file [message #110962 is a reply to message #110943] Fri, 11 March 2005 09:14 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
For tab, use chr(9)
mag@mutation_mutation > select ename||chr(9)||job from emp;

ENAME||CHR(9)||JOB
--------------------
SMITH   CLERK
ALLEN   SALESMAN
WARD    SALESMAN
JONES   MANAGER
MARTIN  SALESMAN
BLAKE   MANAGER
CLARK   MANAGER
SCOTT   ANALYST
KING    PRESIDENT
TURNER  SALESMAN
ADAMS   CLERK
JAMES   CLERK
FORD    ANALYST
MILLER  CLERK

Re: How to place a tab delimiter in output file [message #110966 is a reply to message #110962] Fri, 11 March 2005 09:43 Go to previous messageGo to next message
Naveen Verma
Messages: 60
Registered: August 2004
Member
oh, I am sorry that I didn't specify the thing that I need to place tab in between the field names which I need to write to the file before the execution of sql and some trailer after the sql also. So I need a unix command to place tab.

Thanks for immediate response.

Tthanks
Naveen
Re: How to place a tab delimiter in output file [message #110970 is a reply to message #110943] Fri, 11 March 2005 10:15 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
Forgive my ignorance.
I dont understand your need.
Just spool the sql, you can get the same tab-bed OS file.
or
use awk to create any format you want.
bash-2.03$ cat sample
SMITH   CLERK
ALLEN   SALESMAN
WARD    SALESMAN
JONES   MANAGER
MARTIN  SALESMAN
BLAKE   MANAGER
CLARK   MANAGER
SCOTT   ANALYST
KING    PRESIDENT
TURNER  SALESMAN
ADAMS   CLERK
JAMES   CLERK
FORD    ANALYST
MILLER  CLERK
bash-2.03$ awk '{print $1","$2}' sample
SMITH,CLERK
ALLEN,SALESMAN
WARD,SALESMAN
JONES,MANAGER
MARTIN,SALESMAN
BLAKE,MANAGER
CLARK,MANAGER
SCOTT,ANALYST
KING,PRESIDENT
TURNER,SALESMAN
ADAMS,CLERK
JAMES,CLERK
FORD,ANALYST
MILLER,CLERK

Or please post a sample file- format.
Re: How to place a tab delimiter in output file [message #111376 is a reply to message #110970] Tue, 15 March 2005 17:51 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
> cat t.txt
b c d
h i j
> awk '{print $1"\t"$2}' t.txt
b       c
h       i
Previous Topic: urgent : problem in exporting variables
Next Topic: Error n installation from CD with HP/UX 11.11
Goto Forum:
  


Current Time: Thu Apr 18 21:13:30 CDT 2024