any other way to get trim functionality without transformer
Moderators: chulett, rschirm, roy
-
Nripendra Chand
- Premium Member

- Posts: 196
- Joined: Tue Nov 23, 2004 11:50 pm
- Location: Sydney (Australia)
any other way to get trim functionality without transformer
Hi,
Is there any other way to get trim functionality without using transformer?I checked in modify stage but i couldn't find.
Regards,
Nripendra
Is there any other way to get trim functionality without using transformer?I checked in modify stage but i couldn't find.
Regards,
Nripendra
Hi Nripendra,
I suspect you may have posed a question that is too broad. For example, if you are trying to trim all trailing spaces from all fields where the fields are separted by perhaps a comma, possibilities exist in to do this very efficiently on the unix command line. If you are trying to trim non-printable characters, other options may be more suitable.
It may be helpful if you were to post slightly more details e.g. details what are you trying to trim and other useful info such as the source of your data (e.g. flat file, database, ...).
David
I suspect you may have posed a question that is too broad. For example, if you are trying to trim all trailing spaces from all fields where the fields are separted by perhaps a comma, possibilities exist in to do this very efficiently on the unix command line. If you are trying to trim non-printable characters, other options may be more suitable.
It may be helpful if you were to post slightly more details e.g. details what are you trying to trim and other useful info such as the source of your data (e.g. flat file, database, ...).
David
-
Nripendra Chand
- Premium Member

- Posts: 196
- Joined: Tue Nov 23, 2004 11:50 pm
- Location: Sydney (Australia)
Within DS I think you will have to use the TRIM() function in a transform stage to do this. There are string handling capabilities in the sequential file stage, but they won't work for all types of strings (for instance no implicit trimming will be done when reading quoted strings withi embedded trailing spaces).
Another possibility is, as mentioned, to pre-process the file in unix, though it will depend a bit on the field content. For example, if the field to be used in the lookup is the second field (I could pick the first but have conciously chosen the second to illustrate the point) and the fields in the file are separated by a known character, such a comma, you could pre-process the file very, very (did I mention very?) quickly with "sed"
Thus, with the second field the lookup and comma as a record separator:
This approach is dependent on being able to define a regular expression that will enable you to match all the characters that form the fields up to and including the lookup field. If your field separator character can appear within one of the fields preceeding the look-up field, another approach may be easier.
David
Thus, with the second field the lookup and comma as a record separator:
Code: Select all
sed 's/\([^,]*,[^,]*\) *,/\1,/' your_file_name_here
This approach is dependent on being able to define a regular expression that will enable you to match all the characters that form the fields up to and including the lookup field. If your field separator character can appear within one of the fields preceeding the look-up field, another approach may be easier.
David
-
Nripendra Chand
- Premium Member

- Posts: 196
- Joined: Tue Nov 23, 2004 11:50 pm
- Location: Sydney (Australia)
If you right-mouse click on a column in the input sequential stage and go to "edit row" you will get a window that lets you set many different attributes on a per-column basis. Click on the string attributes at the lower half of the window to see your options, then you can use the online help and/or the .pdf documentation to additional information if you need it.
-
vmcburney
- Participant
- Posts: 3593
- Joined: Thu Jan 23, 2003 5:25 pm
- Location: Australia, Melbourne
- Contact:
There is a modify function called string_trim which is not documented in any DataStage documentation. It does show up in the old Orchestrate manual:
stringField=string_trim [character, direction, justify](string)
You can use this function to remove the characters used to pad variable-length strings of greater length. By default, these characters are retained when the fixed-length string is then converted back to a variable-length string.
The character argument is the character to remove. It defaults to NULL. The value of hte direction and justify arguments can be either begin or end; direction defaults to end, and justify defaults to begin. Justify has no affect when the target string has variable length.
Examples:
name: string = string_trim[NULL, begin](name)
removes all leading ASCII NULL characters from the beginning of name and places the remaining characters in an output variable-length string with the same naem
stringField=string_trim [character, direction, justify](string)
You can use this function to remove the characters used to pad variable-length strings of greater length. By default, these characters are retained when the fixed-length string is then converted back to a variable-length string.
The character argument is the character to remove. It defaults to NULL. The value of hte direction and justify arguments can be either begin or end; direction defaults to end, and justify defaults to begin. Justify has no affect when the target string has variable length.
Examples:
name: string = string_trim[NULL, begin](name)
removes all leading ASCII NULL characters from the beginning of name and places the remaining characters in an output variable-length string with the same naem
Certus Solutions
Blog: Tooling Around in the InfoSphere
Twitter: @vmcburney
LinkedIn:Vincent McBurney LinkedIn
Blog: Tooling Around in the InfoSphere
Twitter: @vmcburney
LinkedIn:Vincent McBurney LinkedIn
-
Nripendra Chand
- Premium Member

- Posts: 196
- Joined: Tue Nov 23, 2004 11:50 pm
- Location: Sydney (Australia)
For trimming null it worked fine. But when i tried to trim spaces, i gave following expression:
C1: string[4] = string_trim[' ', begin](C1)
But it gave following error:
Error in binding: Parsing parameters " , begin" for conversion "string=string_trim[NULL,end,begin](string)": Only one character, or NULL expected, got:
Expected destination field selector, got: ")"; input:
C1: string[4] = string_trim[' ', begin](C1
What should i give to trim spaces?
-Nripendra
C1: string[4] = string_trim[' ', begin](C1)
But it gave following error:
Error in binding: Parsing parameters " , begin" for conversion "string=string_trim[NULL,end,begin](string)": Only one character, or NULL expected, got:
Expected destination field selector, got: ")"; input:
C1: string[4] = string_trim[' ', begin](C1
What should i give to trim spaces?
-Nripendra
-
Nripendra Chand
- Premium Member

- Posts: 196
- Joined: Tue Nov 23, 2004 11:50 pm
- Location: Sydney (Australia)
</a>