문제

I'm still kind of new to RegEx in general. I'm trying to retrieve the names from a field so I can split them for further use (using Pentaho Data Integration/Kettle for the data extraction). Here's an example of the string I'm given:

CN=Name One/OU=Site/O=Domain;CN=Name Two/OU=Site/O=Domain;CN=Name Three/OU=Site/O=Domain

I would like to have the following format returned:

Name One;Name Two;Name Three

Kettle uses Java Regular Expressions.

도움이 되었습니까?

해결책

That sounds like you want substitute&replace based on a regex. How to correctly do that depends on your language. But with sed I would do it like this:

echo "CN=Name One/OU=Site/O=Domain;CN=Name Two/OU=Site/O=Domain;CN=Name Three/OU=Site/O=Domain" |\
sed 's/CN=\([^\/]*\)[^;]*/\1/g'

If you intend to split it later anyway, you probably want to just match the names and return them im a loop. Example code in perl:

#!/usr/bin/perl
$line="CN=Name One/OU=Site/O=Domain;CN=Name Two/OU=Site/O=Domain;CN=Name Three/OU=Site/O=Domain";
for $match ($line =~ /CN=([^\/]*)/g ){
  print "Name: $match\n";
}

다른 팁

assuming you have it in file.txt:

sed -e  's/\/OU=Site\/O=Domain//g' -e 's/CN=//g' file.txt
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top