String extract
Moderators: chulett, rschirm, roy
String extract
Hi
Anyone have any thought on this?
I want to retrieve a text from a column on below logic.
Need to retrive the text start at position 2 characters after keyword "ABC=" till 5 byte or untill a space encountered
e.g:
SourceCol
AHHHNSHHBDHHHSSSUSHUSUUSABC=TESTTTHHSHST output should be - STTTH
AHHHNSHHBDHHHSSSUSHUSUUSABC=TESTT THHSHS output should be - STT
Thanks
Anyone have any thought on this?
I want to retrieve a text from a column on below logic.
Need to retrive the text start at position 2 characters after keyword "ABC=" till 5 byte or untill a space encountered
e.g:
SourceCol
AHHHNSHHBDHHHSSSUSHUSUUSABC=TESTTTHHSHST output should be - STTTH
AHHHNSHHBDHHHSSSUSHUSUUSABC=TESTT THHSHS output should be - STT
Thanks
If your data is in a text file then put the following in the filter command and let awk take care of the parsing. Thats the easiest way I can see. Otherwise you will have to write a C routine and loop through each character.
Actually there is more to the code above, you need to tell me what column it is in the source file and how is it delimited and then I can give you the exact logic. But the meat is what I have posted above
Code: Select all
awk '{print substr($0,index($0,"ABC=")+6,5)}' | awk -F" " '{print $1}'
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Code: Select all
svABCpos <--- Index(InLink.TheString, "ABC", 1)
Field(InLink.TheString[ABCpos+2,5], " ", 1, 1)
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.
I think it would return =TEST from first example as index will keep the first position. Is there any function to return last character of substring in stage variable?ray.wurlod wrote:Code: Select all
svABCpos <--- Index(InLink.TheString, "ABC", 1) Field(InLink.TheString[ABCpos+2,5], " ", 1, 1)
Else we need to add number of search characters in each column derivation
Instead of +2 it would be +5
Field(DSLink3.COL[StageVar+5,5], " ", 1, 1)
Thanks
Esoteric Usage Alert
YourField[1] will return 1 character from the end of the string.
YourField[1] will return 1 character from the end of the string.
Last edited by chulett on Fri Feb 11, 2011 2:31 pm, edited 1 time in total.
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Code: Select all
Right(StageVar,1)
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.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
There's nothing in the original specification that asserts that "TEST" will always follow "ABC=".subrat wrote:I think it would return =TEST from first example as index will keep the first position. Is there any function to return last character of substring in stage variables
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.
Ray, the first solution you have given would work fine, but in that case in we need to add a count till we get the last position of that text and then when we can add '2' again which was my requirement.ray.wurlod wrote:There's nothing in the original specification that asserts that "TEST" will always follow "ABC=".subrat wrote:I think it would return =TEST from first example as index will keep the first position. Is there any function to return last character of substring in stage variables
My only question now is that is there any other function which can return me directly index position of last character in substring (ABC=) in this case.
Hope i make sense,
Thanks
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
I suspect that subrat needs the offset in the original string, but that's just a combination of the Index() function already mentioned and Len() function. The results of each are integers so can be added.
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.