Exporting data into Comma Delimiter.

Hi,

Requirement: Exporting data from Oracle to UNIX into "Comma" delimiter.

Help Needed: I was able to connect to Oracle and import the data. But please let me know while importing the data I need to make it into Comma delimiter flat file.

For Example:
Source Data -
100 ABC TLead
200 XYZ PManager
300 LMN PLead

Target Data to be loaded into Flat File -
100,ABC,TLead
200,XYZ,PManager
300,LMN,PLead

Thanks in advance for your reply.

you can try this...

 
sed -e  's/^[ ]*//g'  -e  's/\([0-9a-zA-Z\.]*\)  */\1,/g' inputfile

Regards,
Usha

1 Like

else, u can write Oracle query which give u comma seperated output

select EMP_ID||','||EMP_NAME||','||LOCATION FROM EMP;

1 Like

Thanks for your replies.

Hi Usha,

Now i am facing another issue.
Source:
8-9KH-1733 07-NOV-08 8-1729UB 04-DEC-08 8-1729UB 1 8-9KH-1733 N Y N N N Y Y Y
8-9KH-4221 07-NOV-08 8-1729UB 07-NOV-08 8-1729UB 0 8-9KH-4221 N Y N N N Y Y Y
8-9KH-534 07-NOV-08 8-1729UB 07-NOV-08 8-1729UB 0 8-9KH-534 N Y N N N Y Y Y
8-9KH-2596 07-NOV-08 8-1729UB 07-NOV-08 8-1729UB 0 8-9KH-2596 N Y N N N Y Y Y
8-9KH-448 07-NOV-08 8-1729UB 07-NOV-08 8-1729UB 0 8-9KH-448 N Y N N N Y Y Y

Target:
I need to remove the SPACES and instead of SPace i need to add a Comma delimiter.

Thanks for your reply.

A perl :

perl -pne 's/\s+[^\n]/,/g' file

---------- Post updated at 02:30 PM ---------- Previous update was at 02:24 PM ----------

This is the right one :(:

perl -pne 's/\s+([^\s+])/,\1/g' file

---------- Post updated at 02:30 PM ---------- Previous update was at 02:30 PM ----------

This is the right one :(:

perl -pne 's/\s+([^\s+])/,\1/g' file
1 Like

Excellent !!!

Thanks alot guys :slight_smile:

With awk:

awk '$1=$1' OFS=\, file
1 Like