Unique records into single line

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
skp
Premium Member
Premium Member
Posts: 135
Joined: Wed Dec 26, 2007 1:56 am
Location: India

Unique records into single line

Post by skp »

Hi All,

Below is my source file format.

Account name,city,value
ABC,hyd,1000
DEF,ban,2000
ABC,Chn,3000
GHI,US,3000
JKL,UK,4000
DEF,us,6600

I need to find unique records I. Account name column and all unique records to populate in single line like below.

Output:
/'ABC/',/'DEF/',/'GHI/',/'JKL/'

Please let me know how to get the desired output.
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

Create a DataStage job to sort/unique followed by Vertical Pivot on first column; replace delimiters as needed.

This can also be done in External Source stage or external filter of Sequential File stage by passing following command:

Code: Select all

awk -F',' '{print $1|"sort -u"}'|awk '{printf "/'"'"'" $1} END {print "/'"'"'"}'
skp
Premium Member
Premium Member
Posts: 135
Joined: Wed Dec 26, 2007 1:56 am
Location: India

Post by skp »

Hi rkashyap,

I tried to do this in unix itself and tried below command

awk -F',' '{print $1}' test2.txt|sort -u |awk '{printf "\\'"'"'" $1} END {print "\\'"'"'"}'

but it's displaying output like
\'A\'B\'C\'

But I need output like below
\'A\',\'B\',\'C\'
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

And... the Awk Clinic is back in session. :wink:

ps. What you "need" seems to have changed.
-craig

"You can never have too many knives" -- Logan Nine Fingers
rkashyap
Premium Member
Premium Member
Posts: 532
Joined: Fri Dec 02, 2011 12:02 pm
Location: Richmond VA

Post by rkashyap »

As Craig noted above, the requirement seems to have changed. For initial requirement try

Code: Select all

awk -F',' '{print $1|"sort -u"}'|awk 'BEGIN {SS=PS="/'"'"'"}{if (NR>1){PS="," SS}} {printf PS $0 SS}'
You can also code a dataStage job for this/these req (see previous post).
Post Reply