Informatica Expression Transformation - informatica

I have an Input port in expression transformation which is middle name field with datatype as string(10). I am using some data quality checks on it and o/p port is having dataype as char(1).
So for eg: If middle name is KUMAR, It should pass only K in output port as I have selected datatype as STRING(1) in O/P port.
But I see, It is not getting truncated and KUMAR is passing through in data. But if I use a variable port in the same expression and give it as STRING(1) and use value received from Variable port in another output port, I see only K letter going through in data.
Why is this happening?

It seems to be very direct requirement. Please use the substr fn as below
substr(middlename,1,1).
Take this value as the o/p port. I hope this should help.

Related

Select multiple variables with Regex inside a single string

Regex101 link
https://regex101.com/r/wOwFEV/2
Background
I have a dump of nmap reports and I want to extract data from to digest.
I have various inputs similar to:
23/tcp open telnet SMC SMC2870W Wireless Ethernet Bridge
The latter three variables change, but the common denominator is:
The first value is ALWAYS 23/tcp
They are ALWAYS separated by more than one space
There will ALWAYS be four values
I would like to use Regex to pluck each "variable" and assign it to a group.
Right now, I have
(?sm)(?=^23\/tcp)(?<port>.*?)\s*open
Which grabs 23/tcp and assigns it to <port>
But I also want to grab:
open and assign it to <state>
telnet and assign it to <service>
SMC SMC2870W Wireless Ethernet Bridge and assign it to <description>
If not an answer, I think knowing how to grab values between '2 or more' white spaces will solve this, but I can't find any similar examples!
A more specific regexp is:
(?sm)(?=^23\/tcp)(?<port>\d+\/\w+)\s+(?<state>\w*?)\s+(?<service>\w*?)\s+(?<description>.*?)\s$
This restricts the port to be digits/alphanumeric, and state and service to be alphanumeric. It only uses .* for the description, since it's arbitrary text.
And with this change, it's not necessary to require that there be at least 2 spaces between each field, it will work with any number of spaces.
DEMO
Nevermind, got it.
(?sm)(?=^23\/tcp)(?<port>.*?)\s{2,}(?<state>.*?)\s{2,}(?<service>.*?)\s{2,}(?<description>.*?)$
Will do exactly what I described.
https://regex101.com/r/wOwFEV/3

Regex smallest capture

I'm trying to find interfaces that contain specific words in the config 'blocks'. E.g.:
!
interface FastEthernet303
description Customer Access
switchport access vlan 40
no ip address
!
interface Vlan1
no ip address
shutdown
!
interface Vlan343
description Customer_LAN
vrf forwarding 1
ip address 1.1.1.1 255.255.254.0
!
interface Dialer1
description 1-1-1
ip flow monitor GO-FLOW input
ip flow monitor GO-FLOW output
keepalive 5 3
!
I want only the interface Dialer1 to be captured.
If I use the '!\ninterface (.?)\n(.).*?\n!' as regex it starts from
the first interface (matches first !\interface etc) and captures accros interface blocks and I want it only to capture blocks with for example the key words 'flow monitor' in them:
interface Dialer1
description 1-1-1
ip flow monitor GO-FLOW input
ip flow monitor GO-FLOW output
keepalive 5 3
I've tried some negative lookup but can't seem to get it right.
Anyone able to help with this please?
The next step would be to extract the interface name but that should be easy once I have the first part.
Many Thanks
Frank
I actually think you can do this without using lookarounds. In the pattern below I use [^!] to cautiously proceed in the pattern without passing an interface marker !.
interface[^!]*flow monitor[^!]*
This answer strongly relies on ! serving as a divider between interfaces. If this not be the case, then my answer is going to have to change.
Demo

How to check the field value value is blank and make it to 0 in informatica powercenter?

I am currently working on a project where there is a scenario in which I have to check the field value(in decimal data type) is blank or not, if it is blank I have to make that particular blank value into 0. How to bring out this logic using expression transformation in informatica powercenter 9.6.1?
Create an output port with the expression:
IIF(ISNULL(field),0,field)
Create a new output port in the Expression transformation and use either of the two expressions.
Expression 1:
Decode(Field,NULL,0,Field)
Expression 2:
IIF(ISNULL(Field),0,Field)
Since the question speaks about blank values as well, you might want to check for '' apart from nulls as mentioned in other answers:
IIF(ISNULL(FIELD) OR LTRIM(RTRIM(FIELD))='',0,FIELD)

How to safely bypass tabs in RegEx

I'm using C to do my regular expressions. Things work except for when the input string contains tabs.
This is my RegEx I plug into the regcomp function:
(DROP).*(tcp).*([\\.0-9]+).*0\\.0\\.0\\.0.*dpt:([0-9]+)(.*)
Regcomp returned OK with no issues.
I then used the following string to do the matching with:
DROP\ttcp\t--\t202.153.39.52\t0.0.0.0/0\ttcp dpt:21
I'm using such string to simulate output of iptables because I want to make a program to see which IPs are already listed.
When I execute my program, I receive the following pieces of output after executing the RegEx where the first line is data from the first offset:
DROP tcp -- 202.153.39.52 0.0.0.0/0 tcp dpt:21
DROP
tcp
2
21
Everything is correct except the second-last value. It shows 2, but I expect it to be 202.153.39.52. and I used ([\\.0-9]+) in my RegEx to try to specifically state I only want numbers and dots to match.
How do I fix my RegEx?
UPDATE
I then proceeded to use this RegEx instead in hopes I get each individual octet of the IP address
(DROP).*(tcp).*([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+).*(0\\.0\\.0\\.0).*dpt:([0-9]+)
This is my result:
DROP tcp -- 202.153.39.52 0.0.0.0/0 tcp dpt:21
DROP
tcp
2
153
39
52
0.0.0.0
21
Now this means the first ([0-9]+) isn't processing properly. I should receive a 202, not a 2. Is there something I'm doing wrong? Do I need a special flag for any RegEx function?
I think you're confused about the difference between regex syntax and that syntax encoded as a string (in languages like Java that don't have first class regexes).
Try something more robust and commonsense:
DROP\s+tcp\s+\S+\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+0\.0\.0\.0/0\s+tcp\s+dpt:(\d+)
This will capture the ip address and the port number only. Why would you want to capture a fixed string like DROP?
As a string, this is:
"DROP\\s+tcp\\s+\\S+\\s+(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})\\s+0\\.0\\.0\\.0/0\\s+tcp\\s+dpt:(\\d+)"
Use an online regex tester like this one for testing and to convert from regex to string automatically.

Regexp to grab protocol from URL

Let's say I have a variable called URL and it's assigned a value of http://www.google.com. I can also received the URL via ftp, hence it'll be ftp://ftp.google.com. How can I have it so I grab everything before the :? I'll have an if/else condition afterwards to test the logic.
/^[^:]+/
If you want to prevent 'www.foobar.com' (which has no protocol specified) to match as protocol:
/^[^:]+(?=:\/\/)/
You mean like this?
/^(.*?):/