Getting a particular record (looping)
Moderators: chulett, rschirm, roy
Getting a particular record (looping)
I have a requirement where the source file has data like
#Z_ABC_FILE
#20121114123456
file1=ABC_SD_1235.txt
file2=
DONE
#Z_ABC_FILE
#20121114123456
file1=DEF_SD_4545.txt
file2=
DONE
#Z_ABC_FILE
#20121114123456
file1=ABC_SD_3454.txt
file2=
DONE
#Z_ABC_FILE
#20121114123456
file1=ABC_FI_3454.txt
file2=
DONE
How to get file1 values or that particular record. I want to know if it can be done with looping.
#Z_ABC_FILE
#20121114123456
file1=ABC_SD_1235.txt
file2=
DONE
#Z_ABC_FILE
#20121114123456
file1=DEF_SD_4545.txt
file2=
DONE
#Z_ABC_FILE
#20121114123456
file1=ABC_SD_3454.txt
file2=
DONE
#Z_ABC_FILE
#20121114123456
file1=ABC_FI_3454.txt
file2=
DONE
How to get file1 values or that particular record. I want to know if it can be done with looping.
Re: Getting a particular record (looping)
Do you need the value from file1 alone, down the line the list will increase?
Thanks
Ram
----------------------------------
Revealing your ignorance is fine, because you get a chance to learn.
Ram
----------------------------------
Revealing your ignorance is fine, because you get a chance to learn.
Wouldn't a simple if-then-else statement work, or is there some additional requirements not detailed in your question?
sv1: if left(inlink.record,6) = "file1" then logic_to_retrieve_the_value else ""
with a simple constraint to only output when data is retrieved?
sv1 <> ""
Regards,
sv1: if left(inlink.record,6) = "file1" then logic_to_retrieve_the_value else ""
with a simple constraint to only output when data is retrieved?
sv1 <> ""
Regards,
- james wiles
All generalizations are false, including this one - Mark Twain.
All generalizations are false, including this one - Mark Twain.
Can't use the col[1,n] = "file1" in the downstream TFM ?jwiles wrote:Wouldn't a simple if-then-else statement work, or is there some additional requirements not detailed in your question?
Thanks
Ram
----------------------------------
Revealing your ignorance is fine, because you get a chance to learn.
Ram
----------------------------------
Revealing your ignorance is fine, because you get a chance to learn.
Hi wittyme,
You may also use a constraint in the transformer-or
a grep command in the filter option of the sequential file stage
You may also use a constraint in the transformer-
Code: Select all
Field(ToT.Col1,"=",1) ="file1"
a grep command in the filter option of the sequential file stage
Code: Select all
grep "file1"
Re: Getting a particular record (looping)
I notice in your sample data all fields appear all the time.wittyme wrote:I have a requirement where the source file has data like
(((sample data)))
How to get file1 values or that particular record. I want to know if it can be done with looping.
It looks like "DONE<NEWLINE>" is your record separator and
"<NEWLINE>" and "=" are your field separators. If my observations are correct, (consistent with all data samples you have) it may help you to look at your data this way and look for features in either a language like sed, awk, BASIC, java or a tool like SQLLDR or in DataStage itself that allows you to set your (multi-byte) record separators and set your field separators. You can then identify fields by field number (again if my observations are correct). You may also want to think in terms of set transformations or events instead of loops. The arrival of each record is a record event, and may be handled by a record handler. The resulting set is a group of records each a set of fields where each result record is transformed from an incoming record. OO languages like Java tend to think in the event model, algebraic languages like SQL tend to think in the set transformation model. This may help you find the language or tool features you want.
Sorry if my answer is less specific than you may have wanted, I am still learning DataStage myself.
Brian Fennell
I read the sequential file as one record and filtered grep = "file1" and in transformer I wrote functions to get the value.
I didn't know in sequential file filter condition we can put grep="file1". Something new I learned
I have done this before using unix commands in sequence job but I want to use parallel job this time so put the question here. Thanks for help!
I didn't know in sequential file filter condition we can put grep="file1". Something new I learned
I have done this before using unix commands in sequence job but I want to use parallel job this time so put the question here. Thanks for help!
Hi wittyme,
If you are using transformer only to get the value of file1 then you can use the below in the filter option-in transformer I wrote functions to get the value
Code: Select all
grep "File1"|nawk -F"=" '{print $2}'
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Yes, but why open another operating system shell when the Field() function within DataStage will do just as well, and more efficiently?
Constraint expression: Left(InLink.TheString,6) = "file1="
Derivation expression: Field(InLink.TheString, "=", 2, 9999)
Constraint expression: Left(InLink.TheString,6) = "file1="
Derivation expression: Field(InLink.TheString, "=", 2, 9999)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.