Create a Pipe Delimited Extract File [message #98551] |
Wed, 29 December 2004 09:08 |
Anindya Banerjee
Messages: 5 Registered: December 2004
|
Junior Member |
|
|
Hi,
I need to call a SQL script that goes against couple of Oracle tables and create an extract file. By default this file is created as a fixed-width file.
Is there a way I can create this file in pipe-delimited format?
Thanks in Advance,
- Anindya
|
|
|
|
|
|
Re: Create a Pipe Delimited Extract File [message #98564 is a reply to message #98557] |
Tue, 04 January 2005 17:15 |
velu
Messages: 10 Registered: February 2002
|
Junior Member |
|
|
yes u can use awk if the output spooled into a file.
awk '{print $1"|"$2"|"$3}' filename > outfilename
if the file is delimited (, comma) then
awk -F, '{print $1"|"$2"|"$3}' filename > outfilename
|
|
|
Re: Create a Pipe Delimited Extract File [message #98568 is a reply to message #98563] |
Wed, 05 January 2005 11:53 |
Anindya Banerjee
Messages: 5 Registered: December 2004
|
Junior Member |
|
|
"....awk '{print $1"|"$2"|"$3}' filename...."
This does not work if you have spaces in the extracted fields. Suppose the field is name and constituted by 'firstname lastname'. This command of awk will assume them to be separate fields.
In such scenario this piece of code works (got this snippet from another website):
awk 'BEGIN{j=split("[[provide the starting columns for the fields e.g. 1 11 39]]",s)}
{for(i=1;i<j;++i){
a=substr($0,s[[i]],s[[i+1]]-s[[i]]);sub(/ *$/,"",a)
printf "%s"(i<j-1 ? "|" : "n"),a
}}' filename;
|
|
|