Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all, I'm using Split function without second parameter in order to parse a column like this
abc | def | ghi
xxx| yyy | zzz
LOAD
SubField(col,'|') as col1,
col
resident S;
It creates a table with 3 rows
abc
def
ghi
and I would like to add a second column with index starting at 1 for each original row ..
abc 1
def 2
ghi 3
xxx 1
yyy 2
zzz 3
Do you know how to do it?
Thanks!
LOAD
RowNO() as NO,
SubField(col,'|') as col1,
col
resident S;
UPDATE :
S:
Load * Inline
[
col
abc | def | ghi
xxx| yyy | zzz
];
FINAL:
LOAD
RowNo() as ID,
TRIM(SubField(col,'|')) as col1,
col
resident S;
Thanks for your answer but it does not start in 1 for each original row so I obtain
abc 1
def 2
ghi 3
xxx 4
yyy 5
zzz 6
instead of
abc 1
def 2
ghi 3
xxx 1
yyy 2
zzz 3
Check my enclosed file which i have updated later on...
But I need the correct value in the "database" if you look in your file ID column doing Ctrl+Tyou will see 1,2,3,4,5,6
For ID calculation try this in Manish's sample app:
Load
If(col=peek('col'),peek('ID')+1, 1) as ID
Like this?
Hi,
Try this scirpt
Data:
LOAD
*,
If(Text <> Previous(Text), 1, peek('ID')+1) as ID;
LOAD
Text,
SubField(Text, '|') AS Value
INLINE [
Text
abc | def | ghi
xxx| yyy | zzz];
Regards,
Jagan.
Hi
This is one more variant of solution:
Data:
Load * Inline
[
col
abc | def | ghi
xxx| yyy | zzz
];
T:
LOAD
-AutoNumber(col)+AutoNumber(col1) as ID,
*;
LOAD
TRIM(SubField(col,'|')) as col1,
col
resident Data;
load col, SubField(col, '|') as s, if(col<>peek(col), 1, peek(id)+1) as id;
LOAD * Inline [
col
abc | def | ghi
xxx| yyy | zzz
];
drop field col;