Hi Guys,
In the following line:
cn=portal.090710.191533.428571000,cn=groups,dc=mp,dc=rj,dc=gov,dc=br
I need to extract this string: portal.090710.191533.428571000
As you can see this string always will be bettween "cn=" and "," strings.
Someone know one regular expression to extract this string?
Any help will be very much appreciated
Best Regards
Pierre
Hi sweetblood,
Tanks a lot for your help!
I used your idea in the following code:
if( /cn=/ )
{
$result = $_;
$result =~ s/^cn=([^,]*?),//;
}
return $result
in this case your REGEX is returning cn=groups,dc=mp,dc=rj,dc=gov,dc=br
I need the opposite result.
I think a REGEX where in the first time remove the string cn=
so the result string will be portal.090710.191533.428571000,cn=groups,dc=mp,dc=rj,dc=gov,dc=br
The second REGEX will remove the entire string cn=groups,dc=mp,dc=rj,dc=gov,dc=br
To be lefting only the needed string portal.090710.191533.428571000
Can you help me?
Regards
Pierre
try this...
echo cn=portal.090710.191533.428571000,cn=groups,dc=mp,dc=rj,dc=gov,dc=br | awk -F "cn=" '{print $2}' | awk -F "," '{print $1}'
---------- Post updated at 12:11 PM ---------- Previous update was at 11:04 AM ----------
euh, rather this...
echo cn=portal.090710.191533.428571000,cn=groups,dc=mp,dc=rj,dc=gov,dc=br | awk -F 'cn=|,' '{print $2}'
maverick-ski:
...
cn=portal.090710.191533.428571000,cn=groups,dc=mp,dc=rj,dc=gov,dc=br
I need to extract this string: portal.090710.191533.428571000
...
Someone know one regular expression to extract this string?
...
Try non-greedy regex match:
$
$ echo "cn=portal.090710.191533.428571000,cn=groups,dc=mp,dc=rj,dc=gov,dc=br" | perl -lne '/^cn=(.*?),/ && print $1'
portal.090710.191533.428571000
$
tyler_durden